I am writing a script by using selenium. My problem is when the chrome has been automatically updated, my script is not working. So, my solution is learning the web chrome version (not driver) at the beginning and run the related chrome driver. So on my desktop I will keep all versions and run the correct one. But I could not find a solution to get the version of chrome. I will kindly appreciate the helps! Thanks in advance!
Try this.
import subprocess
output = subprocess.check_output(
r'wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get Version /value',
shell=True
)
print(output.decode('utf-8').strip())
output
Version=79.0.3945.117
Related
On SikulixIDE, the library webbrowser always open the default browser, even when i use the get method, i tried my code on regular python, it does work. Anyone know why it is reacting like that ?
webbrowser.get('C:/Program Files/Google/Chrome/Application/chrome.exe %s').open(myurl)
Fixed by automating it using a python file and running it trough cmd with base python.exe.
Hello all,
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
dr = webdriver.Chrome(ChromeDriverManager().install(), options=options)
dr.get("url")
cWait = WebDriverWait(dr, 5)
usernameField = cWait.until(EC.presence_of_element_located((By.ID, "txtUserID")))
while running the above set of lines of code, when i click on pycharm run for this python file, it works in headless in good way but when I use
terminal and write code something like
python main.py
the console gives this output
====== WebDriver manager ======
Current google-chrome version is 92.0.4515
Get LATEST driver version for 92.0.4515
Driver [C:\Users\bc62700\.wdm\drivers\chromedriver\win32\92.0.4515.107\chromedriver.exe] found in cache
DevTools listening on ws://127.0.0.1:53298/devtools/browser/b967343c-b07a-43a3-8d1f-d8b41e62e50d
[0906/071237.616:INFO:CONSOLE(19)] "Uncaught TypeError: Cannot read property 'txtUserID' of undefined", source: URL (19)
It is working absolutely fine with pycharm run button, but not with terminal
please help as because of this reason I am not able to make this as schedular event.
When you run it from within pycharm, it is using a specific python, which may be different from your system's default python. Check the run configuration in pycharm and see what the path is to the python version it is using, and try to execute it using the full path to that python, i.e. instead of python main.py it would be something like /path/to/your/project/venv/bin/python /path/to/your/project/main.py
If that's not it, try giving us a more complete explanation of your situation, so that someone can try to reproduce what's happening and investigate further.
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.
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.
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.