Python - Selenium error on Ubuntu - python

I've a strange problem with Python (or maybe I'm only a noob).
I wrote a little bot to automate some action on the browser using selenium and I want to run on a Ubuntu VPS, so I've installed Selenium and the other modules I needed and I ran the script but when it comes to the first of this lines
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "free_play_captcha_types")))
driver.find_element_by_id("free_play_captcha_types").click()
driver.find_element_by_id("free_play_captcha_types").click()
driver.find_element_by_xpath("//option[contains(#value, 'recaptcha_v1')]").click()
I get the socket.error: errno [111] Connection refused error.
I've already tried to run the selenium server before running the script but nothing changes... has someone have an advice?
Thank you in advance.
Another information: I ran the same script on a different VPS and it ran successfully...

Related

Webdriver crashes when using it with Selenium. How to resolve it?

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.

Selenium Servers and Geckodriver don't run at same port

I'm trying to run a Selenium Script (Using PHP) using a Webserver.
I'm working on Kali and to simulate the Webserver I use Xampp.
I tried to run the selenium script on Xampp by the following steps:
-Download the Php Webdriver Bindings, put them in the folder 'htdpcs' of xampp and edit the 'example.php' file following the settings of my own device.
-Download and execute the Selenium Server Standalone, on port :4444.
In the end, I download the geckodriver and I execute the file, but I got the this error:
OSError: [Errno 98] Address already in use
How to fix it in order to run the php-selenium script?
The Selenium Server will fork a geckodriver as soon as it needs one to start a new browser session. You should not start a geckodriver yourself. If you want to use its Webdriver API yourself you can start it with the --webdriver-port argument.

Python selenium: WinError 10053 - host is shutting connection down

I started messing around with Python networking using selenium on Firefox. Unfortunately, I keep getting "ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine".
However, this only happens when running some commands, and it only happens the first time I run them. If execute the command a second time right after that, it works. (See below for a minimal example.)
I found this question, but being a networking newbie I'm having a hard time applying the solution to my situation. How do I prevent the connection from shutting down?
Any help is greatly appreciated!
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com/')
searchfield = browser.find_element_by_id("lst-ib") # Runs without issues
searchfield.get_attribute("value") # Produces WinError 10053
searchfield.get_attribute("value") # Returns '' as it should
EDIT: It seems the error only occurs, when I execute the command in the shell, rather than saving and running the whole script. Nonetheless, it's pretty annoying.
I got the same problem, my config is:
Firefox 60.0.2 (64 bits)
; geckodriver 0.21.0 ( 64 bits)
; selenium 3.12.0
I resolved this problem by downgrade geckodriver to 0.20.1 ( 64 bits)
I had the same problem and tried solutions that were mentioned here but nothing helped me. In the end, it was a very simple solution:
copy the script and the geckodriver to a different folder, and then run it from there. I suppose that in the folder where I always worked I had logs that generated conflicts and that's why this solution worked.

Selenium webdriver support for the latest versions of firefox and chrome

I am using selenium-2.35.0 and Python-2.7.
Testcases are written in python.
my python code to create driver object:
from selenium import webdriver
driver = webdriver.Remote(desired_capabilities={
"browserName": "firefox"
})
And run selenium server by,
java - jar selenium-server-standalone-2.35.0.jar
I had my code working in Firefox - 22 - had the selenium server running, able to run scripts in python, etc. So I'm confident the code works.
Recently, I updated FireFox to 23 and now all I get is
"[Errno 10061] No connection could be made because the target machine actively refused it."
I thought maybe I need to restart the server again, or something. But that seems to do nothing. Is this issue related to selenium webdriver's support for the latest browser version?
But as of this link http://selenium.googlecode.com/git/java/CHANGELOG , selenium supports Firefox - 23. If supported, code that run in Firefox - 22 should also run in Firefox - 23 without any code change.
And how can i make the same code work for chrome?
I have found that the newest version of firefox routinely doens't work immediately well with Selenium. Check out this firefox support matrix on Github that someone made. Unfortunately the only thing you can do is stop Firefox from auto-updating and keep your selenium tests running for firefox newest version minus 1 or 2. Chrome tends to work out of the box for Selenium, sometimes the Beta channel has fixed some selenium issues, so try that if you have a particular issue (on the other hand it may introduce other bugs). So in the end you need to be constantly weary of browser updates and routinely checking how they are working with the current version of selenium.
Check out this guide on how to get Selenium working with rolled back versions of firefox:
http://inkhorn.ca/selenium-python-on-ubuntu-using-firefox/
It will also fix any errors that have to do with “version xul**.0 not defined in file libxul.so”

Cannot create browser process when using selenium from python on RHEL5

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.

Categories