1

I am using Selenium to try and press this button, but Selenium complains that it does not exists

<button name="button" type="submit" class="btn btn-primary"><span class="show-when-enabled"><svg class="bi flex-shrink-0 me-2" height="24" role="img" width="24"><use href="#icon_content-save"></use></svg><span class="pe-3">Save Database/Server</span></span><span class="show-when-disabled"><span class="spinner-border spinner-border-sm"></span><span class="px-3">Please wait, saving record...</span></span></button>

Here is the first command

driver.find_element_by_css_selector("button[type=submit]").click()

This is the second

driver.find_element(By.LINK_TEXT, "Save Database/Server").click() 

and the third command

driver.find_element(By.XPATH, "//a[.//span[text()='Save Database/Server']]").click() 

All three error because Selenium says it does not exists. How should I press the submit button?

0

3 Answers 3

2

Your xpath and css selector seems wrong. there is no anchor tag.

It should have been. XPATH:

driver.find_element(By.XPATH, "//button[.//span[text()='Save Database/Server']]").click() 

Css Selector:

driver.find_element(By.CSS_SELECTOR,"button[type='submit']").click()

LINK_TEXT supports only for anchor tag not button tag.

Sign up to request clarification or add additional context in comments.

2 Comments

For what ever reason the second line of code Css Selector failed. with Error : "ElementNotInteractableException: Message: element not interactable (Session info: MicrosoftEdge=99.0.1150.39) Stacktrace:"
The first line xpath worked. Thank you!
0

Have you tried using wait and action if not use the below.

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains


time.sleep(5)
driver.find_element_by_xpath("yourxPath").click()


WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "YourXpath"))).click()


time.sleep(5)
button = driver.find_element_by_xpath("YourXpath")
driver.execute_script("arguments[0].click();", button)


time.sleep(5)
button = driver.find_element_by_xpath("Xpath")
ActionChains(driver).move_to_element(button).click().perform()

1 Comment

Yes there are waits. This is form I have filled 5 fields with no issue. The last thing I am doing is trying to run submit. I have also tried to run as individual statement once page is fully loaded and still fails. Thank you Akzy.
0

Try it may be work

driver.execute_script("arguments[0].click();", button)

And can you write down the mistake you made?

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.