I'm using pytest with selenium. I have a simple setup:
browser = webdriver.Firefox()
when running the test file with py.test test_foo.py
The firefox browser launched correctly, got the url and executed the test with no problem.
Then i created another python file testsuite1.py which contains
pytest.main('py.test test_foo.py')
I ran python testsuite1.py, it opens the Firefox browser but failed to get the URL and finish the test. The error that it failed on:
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
I googled many different posts on this issue and I couldn't find any solutions. I've updated to Selenium 2.47.1, using Firefox 40. I don't understand why it would work with py.test command and not pytest.main within python.
Any ideas?
Related
I am using webdriver-manager under Robot Framework to automatically manage drivers. I have created a python library where method is defined to get the driver path (see the code snippet below):
#BrowserDriverManager.py
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
def get_browser_driver_path():
driver_path = ChromeDriverManager().install()
return driver_path
I have imported python library under Robot Framework resource and created a keyword for opening application (see the code snippet below).
Open application using browser
${url}= Generate URL for web request via browser
${driverPath}= get_browser_driver_path
Create Webdriver ${BROWSER} executable_path=${driverPath}
Go To ${url}
Now when I am executing test case (under Robot Framework) with only one keyword "Open application using browser" then test executed successfully. See the Success attachment.
However if in the test case there are few keywords before "Open application using browser" then test failed under "Open application using browser". See the Failure attachment.
Failure is happening during the execution of get_browser_driver_path method. I am not sure if keywords executed before having any impact.
Does anyone faced this kind of issue before where keyword execution worked fine in isolation but not in group?
Error is most likely from your environment variables as the error is ValueError: unknown locale: en-US which python doesn't seem to recognize.
I have something like these in my environment:
LC_ADDRESS=en_US.UTF-8
LC_ALL=en_US.UTF-8
LC_COLLATE=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_MEASUREMENT=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_PAPER=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_TIME=en_US.UTF-8
I'm following this online resource, for building an Instagram bot. In it, the instructor uses selenium, which I installed by running: pip3 install selenium
Then he mentioned using ChromeDriver. I downloaded it and installed it following this resource. I tested it and seemingly it worked, however when I tried to use it in my script it crashed, an error message occured: Error sending sync broker message: the pipe is being closed (0xE8)
The script which I ran when the error occurred is:
from selenium import webdriver
class InstaBot:
def __init__(self):
self.driver = webdriver.Chrome()
self.driver.get('https://instagram.com')
InstaBot()
How my I resolve this error? I read through dozens of articles, but still not found what causes. Help is appreciated.
I have checked your code and it works fine for me.
Try to update your chrome browser to the latest version (79.0.3945.130) and download its match ChromeDriver version (79.0.3945.36).
Note that the ChromeDriver should be on the same folder with your code.
So I have been using splinter (wrapper around selenium) to automate a web browser. Recently it stopped working. It opens a browser window but doesn't go to the website.
My code:
import splinter
browser=splinter.Browser()
browser.visit('http://google.com')
The error I get is :
WebDriverException: Message: Can't load the profile. Profile Dir: c:\users\rbarnes\appdata\local\temp\tmpuaskxw If you specified a log_file in the FirefoxBinary constructor, check it for details.
Traceback points to the second line in the code. This worked perfectly fine yesterday.
It seems that a lof of people are having trouble getting Selenium to find chromedriver, so this may apply to them aswell if they actually have the chromedriver.exe in the correct path.
It seems I have everything I need to have these selenium tests working, and when I manually try running the following 2 lines, everything works fine (it finds chromedriver and opens Chrome).
from selenium import webdriver
webdriver.Chrome()
However, when I put the exact same code into a Django test and try running the test through Django, I get a "ChromeDriver executable needs to be available in the path" error. I've tried re-installing Django and Selenium to no success.
Any help would be appreciated!
The problem was actually caused by enabling Celery tasks.
I'm trying to use selenium from python but I'm having a problem running it on a RHEL5.5 server. I don't seem to be able to really start firefox.
from selenium import webdriver
b = webdriver.Firefox()
On my laptop with ubuntu this works fine and it starts a brings up a firefox window. When I log in to the server with ssh I can run firefox from the command line and get it displayed on my laptop. It is clearly firefox from the server since it has the RHEL5.5 home page.
When I run the python script above on the server it (or run it in ipython) the script hangs at webdriver.Firefox()
I have also tried
from selenium import webdriver
fb = webdriver.FirefoxProfile()
fb.native_events_enabled=True
b=webdriver.Firefox(fb)
Which also hangs on the final line there.
I'm using python2.7 installed in /opt/python2.7. In installed selenium with /opt/python2.7/pip-2.7.
I can see the firefox process on the server with top and it is using a lot of CPU. I can also see from /proc/#/environ that the DISPLAY is set to localhost:10.0 which seems right.
How can I get a browser started with selenium on RHEL5.5? How can I figure out why Firefox is not starting?
It looks like the problem I'm encountering is this selenium bug:
http://code.google.com/p/selenium/issues/detail?id=2852
I used the fix described in comment #9 http://code.google.com/p/selenium/issues/detail?id=2852#c9
That worked for me.