Windows authentication popup of my application appears similar to this app https://www.engprod-charter.net/ I had used below code to handle window authentication popup in selenium using python.
from selenium import webdriver
import time
import win32com.client
driver=webdriver.Firefox()
driver.maximize_window()
driver.get('https://www.engprod-charter.net/')
shell = win32com.client.Dispatch("WScript.Shell")
shell.Sendkeys("username")
shell.Sendkeys("{TAB}")
shell.Sendkeys("password#123")
time.sleep(5)
shell.Sendkeys("{ENTER}")
time.sleep(2)
driver.quit()
But since I am using python 2.7.12 for Robot Framework, it seems win32com.client is not supported there. I want to know what library I have to use in Robot Framework to handle this scenario.
I am not asking complete solution as this is not the correct approach in stackoverflow, just want a hint what should I try to handle my scenario. Thanks
You can achieve your scenario using AutoItLibrary which handles window inputs and similar things. Basically controlling the entire GUI not just the browser.
First install AutoItLibrary for Robot Framework
Make sure you have python installed for 32 bit(say python 2.7.6)
Install pywin32-217.win32-py2.7.exe for 32 bit from here
Download AutoItLibrary and unzip the folder
Open command prompt as Administrator and go to downloaded AautoItLibrary folder folder(cd...\AutoItLibrary-1.1.post1) and then write this command and hit enter python setup.py install
Now include AutoItLibrary in Robot Framework
Let us know if this works, I would be interested to know
This can be easily done using Robot Class in java, which can be run in Robotframework test when required.
i.e. A .jar which will function as handler for the windows authentication pop up.
In RobotFramework you would just need to run a .jar which will handle your pop up.
Just in case you are not used to Java, I can help you with a sample code.
Related
I have up and running an Apache Server with Python 3.x installed already on it. Right now I am trying to run ON the server a little python program (let's say filename.py). But this python program uses the webdriver for Chrome from Selenium. Also it uses sleep from time (but I think this comes by default, so I figure it won't be a problem)
from selenium import webdriver
When I code this program for the first time on my computer, not only I had to write the line of code above but also to manually download the webdriver for Chrome and paste it on /usr/local/bin. Here is the link to the file in case you wonder: Webdriver for Chorme
Anyway, I do not know what the equivalences are to configure this on my server. Do you have any idea how to do it? Or any concepts I could learn related to installing packages on an Apache Server?
Simple solution:
You don't need to install the driver in usr/local/bin. You can have the .exe anywhere and you can specify that with an executable path, see here for an example.
Solution for running on a server
If you have python installed on the server, ideally >3.4 which comes with pip as default. Then install ChromeDriver on a standalone server, follow the instructions here
Note that, Selenium always need an instance of a browser to control.
Luckily, there are browsers out there that aren't that heavy as the usual browsers you know. You don't have to open IE / Firefox / Chrome / Opera. You can use HtmlUnitDriver which controls HTMLUnit - a headless Java browser that does not have any UI. Or a PhantomJsDriver which drives PhantomJS - another headless browser running on WebKit.
Those headless browsers are much less memory-heavy, usually are faster (since they don't have to render anything), they don't require a graphical interface to be available for the computer they run at and are therefore easily usable server-side.
Sample code of headless setup
op = webdriver.ChromeOptions()
op.add_argument('headless')
driver = webdriver.Chrome(options=op)
It's also worth reading on running Selenium RC, see here on that.
I am attempting to write a script to automate the setup of a new development machine. I have been using PyWinAuto to try to automate the installation of various programs which mostly use WinForm (or similar) GUI windows.
PyWinAuto opens the application properly, but does not return any windows. I have installed SWAPY and it shows me controls that I expect to see, but they do not work in the code. I tried using PyWinAuto 0.6.3 as well as 0.5.4 with Python 2.7.13 and 2.7.12 respectively (I am on a Windows 7 32-bit machine) and nothing has worked.
Here are examples of errors I am getting:
import pywinauto
from pywinauto.application import Application
app = Application()
app.Start("C:\setup.exe")
appSetup = app.Setup
appSetup.Wait('ready')
...
...
Error: pywinauto.timings.TimeoutError: timed out
or
app = Application()
app.Start("C:\setup.exe")
appSetup = app.Setup
appSetup.ClickInput()
...
...
Error: pywinauto.findbestmatch.MatchError: Could not find 'Setup' in '[]'
Here is an example of one installation that I am getting errors on:
Boost Install Window with SWAPY Description
Your help is much appreciated. Thank you!
This problem occurs when the application you are targeting spawns a new process after starting. To fix this problem (with help from #VasilyRyabov - thank you!), I start the application as I did before (app.start("C:\setup.exe") and then connect the application (app.connect(title="Setup")) so you are connected to the process that is running the GUI window.
In some cases I have had to add a delay between these two functions if it does not spawn the second process fast enough.
This issue posted on GitHub is very similar to this scenario.
I am using selenium to open a web browser (specifically Chrome) in order to login to an account. When I run my script, there is a modal dialog box that lets the user know there is an error with administrative permissions. Once the user clicks "Okay", the rest of the script runs without issue.
The problem is I need this script to run automatically. Is there a way to use Python to click the "Okay" button? The alert is not within Chrome, so .switch_to_alert() is not helpful. I've found this question asked previously but the response makes it clear it can't be done with selenium, but can it be done another way?
I've also found this source on using ctypes to handle, but I'm unable to install ctypes.
Any tips/help would be appreciated!
I did further research and it appears that a system modal dialog box cannot be accessed with Python.
I was able to prevent the pop up from occurring at all by getting an older version of the chromedriver. Instead of the most updated (ChromeDriver 2.30), I reverted back to ChromeDriver 2.27 and my program worked without issue.
I am trying to crontab a python/selenium script but obviously this won't work since Firefox requires a display, I went down the PyVirtualDisplay / xvfb route but this won't give me visual feedback, I don't want to run the script headless,I just want it to launch automatically like if I was entering the command line by hand in the terminal, just automatic . Would you know of a way to do it without going through the crontab/headless route ?
thank you ,
If you want to run your test in background but same time you can see browser when you want, try this:
Install CI and run it service by your user (try Jenkins, google will help you)
Write Ant Script, it will help to automate the run. (URL)
I'm using CI and Ant to run my test by schedule and when i want buy one click. Good luck maybe this will help you.
I have a Python script that uses Selenium WebDriver (with PyVirtualDisplay as the display) to log into Flickr.
http://pastebin.com/dqmf4Ecw (you’ll need to add your own Flickr credentials)
When I run it as myself on my Debian server, it works fine. (I’m a sudoer, but I don’t use sudo when running the script.)
When I run it as the user www-data (which is what it’ll be running as eventually, because I want to trigger it from a Django website), I get two problems, one small, one big:
(Small): the webdriver.Firefox() call takes 30–45 seconds to return, compared to 2 seconds when run as myself
(Big): the script fails to log into Flickr. In order to log in, I find the username and password fields on the Flickr signin page (http://www.flickr.com/signin/), and use element.send_keys() to enter the username and password. Although Selenium seems to find the elements (i.e. no NoSuchElementException is thrown), the values do not get entered in the fields when the script is run as www-data (according to the screenshots I take using browser.save_screenshot), unlike when the script is run as myself.
Why does send_keys() not work when the script is run as www-data? (And is it related to the browser taking much longer to start?)
Maybe you have something different in your environment.
Try copy by example your ~/.bashrc in /home/www-data
If it's not sufficient, run this command both as your current user & as www-data:
strace -tt -f -s 1000 -o /tmp/trace ./script.py
And paste it (filter out your logins/passwords) somewhere.
We will see what's happens.
Sometimes, Firefox performs some nasty plugin compatibility check during startup. As each user can have a different set of browser plugins, this could be responsible for the difference in startup times. You could try to sync your Firefox profiles between users.
Then, are you sure that Firefox as user www-data has proper network/internet access? Can you confirm that the Flickr site loads properly via SeleniumHQ? "The script fails to log into Flickr" is too unprecise. Some more details about why it fails might reveal the problem instantaneously.
Edit: Sorry, I just understood that there shouldn't be a difference in profiles, because Selenium creates one. Nevertheless, my second point might be useful, so I won't delete this answer.
Some more things to ponder about:
Could you spawn firefox manually from www-data account once and make sure that Firefox is not updating itself before every execution of the script? I once faced this problem with Selenium RC on Windows and had to let the update finish before starting the script with the updated binary.
As a workaround, I guess you could you try running the script as www-data user but connecting remotely to a webdriver server running in your login (aka "grid" mode). Would that work for you?
I would suggest getting the latest chrome from google and trying input.send_keys() in that browser instead.
Sometimes some features of webdriver get broken with new releases.. If you are bent on testing with firefox, you might have better luck with an older/newer version of selenium webdriver.
I remember having a similar issue regarding send_keys() on a mac.. My issue was that send_keys() did not work in certain modal windows after I updated selenium webdriver.. I fixed it by reverting to an older webdriver that I knew to work. However, I was using Ruby and not Python to drive webdriver.
sometimes, there might also be a problem with getting the correct ENV variables in your shell if you use it as a different user. I would suggest trying to troubleshoot and see if all the shell ENV variables are set properly under www-data.