1

I am attempting to click a save button but Selenium (with Python) is having issues. I keep getting the error, "Message: no such element: Unable to locate element"

Here is the HTML

<input type="submit" name="action[save]" class="FixedRight SPSubmitRequest button save-button disabledsubmit" value="Save">

And the XPath

//*[@id="spsisFunctionJSAutoFormID12"]/table/tbody/tr/td[3]/input

I have attempted the following to no avail

driver.find_element_by_xpath('//*[@id="spsisFunctionJSAutoFormID12"]/table/tbody/tr/td[3]/input').click()

driver.find_element_by_class_name('FixedRight SPSubmitRequest button save-button disabledsubmit" value').click()

driver.find_element_by_xpath('//button[@name='Save'].click()

None of these work and all produce the same error

3 Answers 3

0
driver.find_element_by_xpath('//*[@id="spsisFunctionJSAutoFormID12"]/table/tbody/tr/td[3]/input').click()

Without the rest of the DOM it's hard to tell what might be wrong with this one.

driver.find_element_by_class_name('FixedRight SPSubmitRequest button save-button disabledsubmit" value').click()

You accidentally copy+pasted in " value.

driver.find_element_by_xpath('//button[@name='Save'].click()

According to your snippet, the name is action[save] and the quotes are slightly off.

Try driver.find_element_by_xpath('//button[@value="Save"]').click();

3
  • Thank you for the feedback! So it ended up being that the class name was hidden for some reason. Commented Sep 18, 2021 at 18:32
  • //button[@value="Save"] this wouldn't work because the web element is an input tag and not a button. Commented Feb 15, 2022 at 10:06
  • Change button to the appropriate tagName or use the * wild card.
    – kirbycope
    Commented Feb 16, 2022 at 0:12
0

I tried with these 2 statements in Selenium + Java and they worked as expected:

System.out.println(driver.findElement(By.xpath("//input[@name='action[save]']")).isDisplayed());

System.out.println(driver.findElement(By.cssSelector("input[class='FixedRight SPSubmitRequest button save-button disabledsubmit']")).isDisplayed());

You can change the syntax to Python. It may be something like:

driver.find_element_by_xpath("//input[@name='action[save]']").click()

driver.find_element_by_css_selector("input[class='FixedRight SPSubmitRequest button save-button disabledsubmit']").click()
-1

In outsourced qa testing we can create multiple type of locators for this element using attribute, css and xpaths. One of the most effective method using xpath for locating the element is using value i.e //input[@value='Save']. For xpath cheat sheet please refer the below link for more details to create effective xpaths https://www.lambdatest.com/blog/most-exhaustive-xpath-locators-cheat-sheet/.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.