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.

4
  • Can you show the page? Commented Mar 3, 2019 at 12:06
  • seems locator is wrong, share page's source code for this element. Commented Mar 3, 2019 at 12:11
  • 1
    Share your HTML, please. Commented Mar 3, 2019 at 13:01
  • That button probably gets added late. Commented Mar 4, 2019 at 0:29

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

3 Comments

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.
This solution worked. I updated the chromedriver to the latest version and it works smoothly now, thank you sir
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.