1

I'm writing a code which uses Selenium. To test out a the find_element_by_css_selector function I wrote the following code:

self.browserProfile = webdriver.ChromeOptions()
self.browserProfile.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})
self.browser = webdriver.Chrome('Chrome_Driver/chromedriver', chrome_options=self.browserProfile)
self.email = email
self.password = password
self.browser.get('http://samplePage.html')
inputs = self.browser.find_element_by_css_selector('button')
print(inputs)

But I get the following error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"button"}
  (Session info: chrome=70.0.3538.77)
  (Driver info: chromedriver=2.25.426924 (649f9b868f6783ec9de71c123212b908bf3b232e),platform=Linux 4.15.0-45-generic x86_64)

How do I solve this error? The chromedriver and all required dependencies are fulfilled I am running python 3.6.

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
RishiC
  • 768
  • 1
  • 10
  • 34

1 Answers1

1

This error message...

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"button"}

...implies that the ChromeDriver was unable to locate the desired WebElement through the Locator Strategy which you have used.

The relevant HTML would have helped us to analyze your issue in a better way. However your main issue is the incompatibility between the version of the binaries you are using as follows:

  • You are using chromedriver=2.25
  • Release Notes of chromedriver=2.25 clearly mentions the following :

Supports Chrome v53-55

  • You are using chrome=70.0
  • Release Notes of ChromeDriver v2.45 clearly mentions the following :

Supports Chrome v70-72

  • Your Selenium Client version is unknown to us.

So there is a clear mismatch between ChromeDriver v2.25 and the Chrome Browser v70.0

Solution

  • Keep Selenium upgraded to current levels Version 3.141.59.
  • Upgrade ChromeDriver to current ChromeDriver v2.46 level.
  • Keep Chrome version between Chrome v71-73 levels. (as per ChromeDriver v2.46 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 through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Execute your @Test.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    I'm not really sure why someone downvoted you. You explained the problem and multiple aspects of a solution for OP to solve it himself. – NoSplitSherlock Mar 03 '19 at 15:33
  • 1
    This solution worked. I updated the chromedriver to the latest version and it works smoothly now, thank you sir – RishiC Mar 04 '19 at 06:03
  • Great news !!! I was sure about the actual problem of _version incompatibility_ where as @NoSplitSherlock 's support gave us the confidence that we were walking in the right direction to address your issue. – undetected Selenium Mar 04 '19 at 08:03