Currently I'm using multiple exceptions in a for loop. However, they are still throwing exception errors and I'm not certain why they are not being handled.
Here is my code:
for x in range (15):
actions.click_and_hold(element1).move_to_element(element2).release().perform()
try:
WebDriverWait(driver, 5).until(
EC.visibility_of_element_located((elementLocator))
)
return True
except (StaleElementReferenceException, TimeoutException):
break
Here is the error being thrown:
StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: headless chrome=67.0.3396.30)
(Driver info: chromedriver=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8),platform=Mac OS X 10.13.4 x86_64)
I don't see any issue in your code block as such but your main issue seems to be in the version compatibility between the binaries you are using as follows :
You are using chromedriver=2.36
Release Notes of chromedriver=2.36 clearly mentions the following :
Supports Chrome v63-65
You are using chrome=67.0
Release Notes of ChromeDriver v2.38 clearly mentions the following :
Supports Chrome v65-67
So there is a clear mismatch between the ChromeDriver version (v2.36) and the Chrome Browser version (v67.0)
Solution
Upgrade ChromeDriver to current ChromeDriver v2.38 level.
Keep Chrome version at Chrome v67.x levels. (as per ChromeDriver v2.38 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test.
Related
I've been using Selenium with the Edge Driver for some time. I've been instantiating my Edge Driver by specifying the executable_path= parameter with no issues. However, I recently switched my web automation project to use the webdriver_manager, i.e., webdriver_manager.microsoft import EdgeChromiumDriverManager. Now, when I command the driver to navigate to any webpage - it opens for one second, then immediately closes. The current troubleshooting step I'm on is ensuring that the Edge Driver I'm using (the one downloaded by using the webdriver_manager module) is compatible with my current OS Version, but now I'm stumped. I don't know how to find which MS Edge Driver is compatible/correct for my current OS build - I see no patterns when comparing the two, e.g.:
My current OS:
The webdriver downloaded by the webdriver_manager:
And here is a link to all MS Edge Drivers:
https://msedgewebdriverstorage.z22.web.core.windows.net/
So, how do I find the Edge Driver that is "right" for my OS? When I look at these two numbers: OS build - 22000.795 and Edge webdriver version - 103.0.1264.77; I see no pattern or way of determining which driver is compatible. Maybe, I'm using the webdriver_manager module improperly? I know I can use the executable path, but I'm under the impression that using the webriver_manager automates the install of new releases for you so you don't have to update your script to new edge drivers in the future.
For additional context, here is my code (using Facebook's domain just as an example):
from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(service = EdgeService(EdgeChromiumDriverManager().install()))
driver.get('https://facebook.com')
The SeleniumBase driver manager works well with Edge:
from seleniumbase import get_driver
driver = get_driver("edge", headless=False)
driver.get("https://facebook.com")
import time; time.sleep(1)
driver.quit()
(Here's another example using the raw driver manager: raw_browser_launcher.py)
Alternatively, you can use the more simple format with automatic setUp and tearDown, but then you need to run your test with pytest and add --edge as a command-line option to use Edge:
from seleniumbase import BaseCase
class MyTestClass(BaseCase):
def test_facebook(self):
self.open("https://facebook.com")
self.sleep(1)
pytest test_facebook.py --edge
========================= test session starts ==========================
platform darwin -- Python 3.10.5, pytest-7.1.2, pluggy-1.0.0
rootdir: /Users/michael/github/SeleniumBase/examples, configfile: pytest.ini
plugins: html-2.0.1, xdist-2.5.0, forked-1.4.0, rerunfailures-10.2, ordering-0.6, cov-3.0.0, metadata-2.0.2, seleniumbase-3.5.11
collected 1 item
test_facebook.py .
========================== 1 passed in 4.40s ===========================
It's working now (i.e., with the same code example in my original question, the MS Edge window now opens as commanded and remains open). I found the MS Docs regarding Edge webdriver installation/configuration
https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=c-sharp
and here are the steps I followed:
The first step is to ensure that your Edge webdriver ("msedgedriver.exe") version matches your Edge browser version (I read a tech blog that said my OS build version needed to match my "msedgedriver.exe" version - thinking maybe that's wrong now?)
I navigated to About Microsoft Edge in settings: edge://settings/help
which displays my current MS Edge version - It was covered with a prompt to update Edge - so I did. Checked after update and my version was: 104.0.1293.47
On a whim, suspecting that maybe my Edge browser update was the cause for webdriver_manager downloading the incompatible msedgedriver.exe, I attempted to run my script again (exact same one I posted in original question)
And it worked - I checked the msedgedriver.exe version right after and noticed that webdriver_manager downloaded a new version: 104.0.1293 - which matches my current Edge Browser version.
So, I'm not 100% sure what the cause for the webdriver_manager failing to download the correct version (to match my browser) was - but until I updated my MS Edge Browser, no new drivers were installed. Then after update and running the script, the right driver is installed and it's working fine now.
Using selenium webdriver with Edge browser. Worked fine until last night/morning. Errors are:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of MSEdgeDriver only supports MSEdge version 96
Current browser version is 98.whatever. It says the application was modified on 2/3 of this year, which I didn't consent to as far as I can remember.
Why did that catch? Did it automatically install an update without letting me know? Why would that be?
In any case, TLDR, how do I fix this?! and which does Selenium dislike: my edgeDriver, or Selenium being out of date? should I REVERT EdgeDriver by finding an older version (how?), or would it be best to update Selenium somehow?
I am just getting started with Selenium. Right now I'm using Python. I tried this:
from selenium import webdriver
driver = webdriver.Edge()
and got the error message:
WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687
So I followed the link and downloaded the latest version, but got a new error:
driver = webdriver.Edge('edgedriver_win64\msedgedriver.exe')
SessionNotCreatedException: Message: session not created: This version of MSEdgeDriver only supports MSEdge version 90
Current browser version is 81.0.416.77 with binary path C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
Now I don't know what to do. The earlies version for the webdrvier found from the download link is 88.
Update edge browser or use a previous version of driver
You can download previous version from:
https://msedgewebdriverstorage.z22.web.core.windows.net/
Click next page till you get the version you want ,
Pretty straightforward. On a Mac, using chromedriver in python. Here is the code:
from selenium import webdriver
EXE_PATH = r'chromedriver'
driver = webdriver.Chrome(executable_path=EXE_PATH)
driver.set_window_size(1024, 768)
driver.get('file:///index.html')
But it always crashes on the line:
driver.set_window_size(1024, 768)
The error it gives:
selenium.common.exceptions.WebDriverException: Message: unknown error:
cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
(Session info: chrome=75.0.3770.80)
(Driver info: chromedriver=2.29.461585 (0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),platform=Mac OS X 10.13.6 x86_64)
As you can see my chrome version is 75.0.3770.80 and my chromedriver version is 2.29.461585. I believe these versions should work together. Is this a version mismatch issue or something else?
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error:
cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=2.29
Release Notes of chromedriver=2.29 clearly mentions the following :
Supports Chrome v56-58
You are using chrome=75.0
Release Notes of ChromeDriver v75.0 clearly mentions the following :
Supports Chrome v75
So there is a clear mismatch between ChromeDriver v2.29 and the Chrome Browser v75.0
Solution
Upgrade ChromeDriver to ChromeDriver v2.75 level.
Keep Chrome version at Chrome v75 levels. (as per ChromeDriver v2.75 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
I've been working with the following code, trying to introduce myself to selenium. When it runs, the chrome browser opens, but the page is blank, with no source code a far as I can tell, and 'data;' in the address bar. Any information on why this is happening would be greatly appreciated.
from selenium import webdriver
browser = webdriver.Chrome(service_args = ['--ignore-ssl-errors=true', '--ssl-protocol=TLSv1'])
url = 'https://www.google.com/'
browser.get(url)
I have also tried it without the service_args and tried it specifying the driver path and both, but get the same result each time
The most possibility is your browser not compatible with the webdriver. Please confirm your browser version and webdriver version.
My chrome version is 60 and chromerdriver is chromedriver_2.30.exe
You can find compatible version from here
Update the chromedriver and Chrome Browser, sometime I also faced this issue.
I don't see any error as such in your code. Though the documentation for service_args is missing in the Selenium-Python API Docs as well as in the ChromeDriver Getting started Doc. But 0096850 clearly suggests service_args is implemented.
The service_args works well at my end. Hence I suspect there is a mismatch between Selenium version, chromedriver version and Chrome version we are using. First and foremost, we have to ensure that our Selenium version, chromedriver version and Chrome version are compatible. You can find the compatibility information on the Downloads page of ChromeDriver individually for each releases.
The Downloads page clearly mentions:
Latest Release: ChromeDriver 2.32 Supports Chrome v59-61
Additionally, you may be required to pass the argument executable_path to mention the absolute path of the chromedriver binary as follows:
Windows 8 based code:
from selenium import webdriver
browser = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe', service_args = ['--ignore-ssl-errors=true', '--ssl-protocol=TLSv1'])
url = 'https://www.google.com/'
browser.get(url)
I've met the same problem,but I solved it by updating my webdriver
Update your webdriver of chrome ,here is the link https://sites.google.com/a/chromium.org/chromedriver/downloads
If you're using Codeception, start the test with :
$I->amOnPage('/');
simply add this argument to selenium options (google how add options on solenium python to how to add options argument)
options.add_argument("--remote-debugging-port=9225")