I’m trying to click the Next button using Selenium, I’ve tried with the code below, but it ends in error.
The element
<input type="submit" name="submitNext" value="Next">
My code
driver.find_element_by_name("submitNext").click()
But then it outputs these errors:
Traceback (most recent call last): File "C:/Users/thomas/PycharmProjects/test/mainapp/main.py", line 194, in <module> visa() File "C:/Users/thomas/PycharmProjects/test/mainapp/main.py", line 174, in visa driver.find_element_by_name("submitNext").click() File "C:UsersthomasPycharmProjectsBudgetMainvenvlibsite-packagesseleniumwebdriverremotewebdriver.py", line 487, in find_element_by_name return self.find_element(by=By.NAME, value=name) File "C:UsersthomasPycharmProjectsBudgetMainvenvlibsite-packagesseleniumwebdriverremotewebdriver.py", line 955, in find_element 'value': value})['value'] File "C:UsersthomasPycharmProjectsBudgetMainvenvlibsite-packagesseleniumwebdriverremotewebdriver.py", line 312, in execute self.error_handler.check_response(response) File "C:UsersthomasPycharmProjectsBudgetMainvenvlibsite-packagesseleniumwebdriverremoteerrorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"submitNext"} (Session info: chrome=66.0.3359.170) (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 10.0.16299 x86_64)
How can I click that button without errors?
Advertisement
Answer
This error message…
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"submitNext"} (Session info: chrome=66.0.3359.170) (Driver info: chromedriver=2.36.540470)
…implies that the ChromeDriver was unable to locate the desired element.
Locating the desired element
As per the HTML you have shared to click on the element you can use either of the following Locator Strategies:
css_selector
:driver.find_element_by_css_selector("input[name='submitNext'][value='Next']").click()
xpath
:driver.find_element_by_xpath("//input[@name='submitNext' and @value='Next']").click()
However your main issue is 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=66.0
- Release Notes of ChromeDriver v2.38 clearly mentions the following:
Supports Chrome v65-67
- Your Selenium Client version is unknown to us.
So there is a clear mismatch between the ChromeDriver v2.36 and the Chrome Browser v66.0
Solution
- Upgrade Selenium to current levels Version 3.11.0.
- Upgrade ChromeDriver to current ChromeDriver v2.38 level.
- Keep Chrome version at Chrome v66.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
.