I have used Selenium in the past and was pretty happy with it.
When I started a new project I wanted to use it again. Since it has been a long time and my ChromeDriver 2.20 didn't seem to work I updated to 2.25. This seemed to work but that's only an illusion.
It seems the driver.get("whateveryouputhere") never fully loads the page.
from selenium import webdriver
driver = webdriver.Chrome('/Users/Sascha-mac/Desktop/chromedriver')
driver.get("http://www.python.org")
driver.close()
This does open a Chrome tab that navigates to www.python.org as you'd expect it to. However, it doesn't close the driver.
Even a simple print "HELLO" doesn't come through until I manually close Chrome.
I have updated to the newest version of Selenium, ChromeDriver. I work on MacOS Sierra with Python 2.7. I have also tested with different websites - no difference.
Where did I go wrong?
driver.close() closes the window.
driver.quit() terminates the browser.
macOS apps that have multiple documents generally do not terminate when the last window is closed. The macOS convention is that only single window apps should do that and traditionally few of those do that.
You might be confused by the common Windows behavior.
Related
The relevant code is as follows:
# find the Chromium profile with website caches for the webdriver
chrome_options = Options()
profile_filepath = "user-data-dir=" + "/home/hephaestus/.config/chromium/Profile1"
chrome_options.add_argument(str(profile_filepath))
# put chromium into --no-sandbox mode as a workaround for "DevToolsActivePort file doesn't exist"
chrome_options.add_argument("--no-sandbox")
# start an automatic Chrome tab and go to embervision.live; wait for page to load
driver = webdriver.Chrome("./chromedriver", options=chrome_options)
When I run this Python code (and import the needed libraries), I get the screenshot below. Chromium that was opened with the above code is on the right, and is transparent and glitching out.
Desktop view with Chromium webdriver tab glitching out on the right
I am able to enter web addresses and interact with the page, but I just can't see any of it. I'm not sure why.
I deleted and re-downloaded Selenium and Chromium, to no avail. I had to add the "--no-sandbox" option because it was getting another error that said "DevToolsActivePort file doesn't exist".
I'm not sure what else is causing this issue.
So I found a solution that works for me!
Uninstall and reinstall Chromium completely. When reinstalling, check that your Chromium version matches with Selenium (which I didn't even know was a thing).
DO NOT run your Python code as a sudo user. I did "sudo python3 upload_image.py" and got the "DevToolsActivePort file doesn't exist" error. When I ran just "python3 upload_image.py", it did not raise the error.
Do not use the option "--no-sandbox" when running as a non-sudo user ("python 3 upload_image.py"). For some reason, the "--no-sandbox" option also broke my Chromium browser in the same transparent/infinite way as I posted above.
Hope this helps someone in the future!
I have this python program made with selenium that automates a search on a firefox page, with a login and everything.
The thing is, after the search is done, the program stops executing (the page is still open. I want it that way) but I want to somehow implement a function that when -given certain argument- it searchs for something different on that open firefox page.
I don't know if I explained myself, but this is very important to me.
If you know how to do this but with Chrome I don't mind. I only need it to work regardless of the browser.
I'm not that pro at this, so please be patient with me. I'm very grateful for all the help you could provide me.
Thanks!!
https://en.wikibooks.org/wiki/Python_Programming/Interactive_mode:
Python has two basic modes: script and interactive. The normal mode is
the mode where the scripted and finished . py files are run in the
Python interpreter. Interactive mode is a command line shell which
gives immediate feedback for each statement, while running previously
fed statements in active memory.
So basically you need to run your code in interactive mode. It depends on your IDE: If you use PyCharm Right-click on the page that you're writing your code and find Run File in Python Console and continue coding in the new window opened by PyCharm. You can also use Jupyter which is a great tool for interactive mode. For other IDEs, try to find any menu that is related to interactive mode or window.
I'm a bit of a novice to all of this, but I had written a simple web scraper in Python a few months ago that interfaced to Chrome using Selenium and chromedriver (it used to work with v90). I'd run this script every couple of weeks or so to get new data, but when I went to run it today it wouldn't work. I got a message that said "chrome not reachable". I can see where the chromedriver window launches (it says, "this window being controlled by automated software"), but my script cannot communicate with that window. It will eventually timeout and throw the "chrome not reachable" error.
I thought that this might have to do with the latest chrome updates, so I updated my chromedriver version, but the issue persists. Has anyone seen this recently and do you know a workaround?
I'm using:
Python v3.9.4
Selenium v3.141.0
And I've tried:
ChromeDriver v92.0.4515.43
ChromeDriver v91.0.4472.101
ChromeDriver v90.0.4430.24
Thanks for any insight!
Your chromedriver and Chrome versions must match, otherwise chromedriver will not work. You can try installing an earlier version of Chrome with matching chromedriver and give it a try. You can find earlier versions here: https://www.slimjet.com/chrome/google-chrome-old-version.php
Well, I didn't change anything; I didn't reboot, I didn't alter my code, I didn't re-download the chromedriver, but today I ran my script and it all works as normal. I don't know what happened earlier.
This is not a great answer, but I don't want others to waste time trying to solve a non-existing problem. Thanks all for your help and insight.
This problem really confused me a lot.
I'm using python selenium do some automatic work. After the work done, i need to close browser(I must use firefox). And I know driver.close() is to close current window and driver.quit() will close all windows and exit browser. The problem is: it doesn't work for me if i am using python file.py to run my code, but work if I setup the driver in python console, here not work is to say it just close my url, but the firefox browser not exit. All above tests have setted firefox_profile.
More, i found if i don't set firefox_profile the first way to run my code also working. I think maybe it's a bug for firefox_profile. Wish someone to save my day.
My code is just like:
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # custom location
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', download_dir)
profile.set_preference(
'browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
driver = webdriver.Firefox(
executable_path=gecko_dir, firefox_profile=profile)
driver.get(someurl)
driver.quit()# which will close my session, my url, my current window but not exit browser
the versions i'am using:
python 3.5.3
selenium 3.4.3
firefox 55.0.1
geckodriver 0.18.0
While we work with Selenium 3.5.0 with latest GeckoDriver v.0.18.0 and Mozilla Firefox 53.0, the browser window(s) initiated by the WebDriver instance is bound to get destroyed (killed) once you invoke the quit() on the WebDriver instance.
So the blank window which you are seeing may be a result of either some other user interactions or a dangling instance.
Recommendation:
You can consider the following steps to start a clean Test Execution:
Run CCleaner tool to wipe out all the leftovers from your previous executions.
Restart your system to start your Test Execution on a clean OS environment.
Keep the Test Environment isolated from other User Interactions.
I made a PyQt program which runs Chrome web driver via Selenium.
It works normally in Mac or Linux, but it prints a weird line in console when I run this program on Windows, as below.
KLIB_SelfTest return : KLR_OK
The log itself is not a big deal, but when it comes with Pyinstaller, it produces some error when compiled by --noconsole option. When I remove that option it works fine, but I want the console window not to be showed.
Moreover, I'm really curious about which part of the Chrome driver produces that log. I searched almost every information as far as I can, but I couldn't find anything related with the log.
Thanks in advance for your help.