New_Py_Guy
New_Py_Guy

Reputation: 53

Cannot click "Save" button (selenium webdriver - python - chrome)

I am fairly new to Python and started learning. I am trying to automate data entry. I am stuck at the "save" button. How do I find the right information and click it to save?

Thank you so much

PyGuy


Element

<input type="submit" value="Save">

Xpath

//*[@id="decorated-admin-content"]/div/div/form/div[10]/div/input

Selector

#decorated-admin-content > div > div > form > div.buttons-container > div > input[type="submit"]

On my python script, I have entered

from selenium import webdriver
from selenium.webdriver.common.by import By

driver.findElement(By.xpath("//input[@type='submit'and @value='save']")).click()
# I also tried below
# driver.findElement(By.xpath("//input[@type='submit'][@value='Save']")).click();
# driver.findElement(By.xpath("//*[@id="decorated-admin-content"]"))

Upvotes: 0

Views: 1995

Answers (2)

Lucas Tierney
Lucas Tierney

Reputation: 2563

If you're using python, the syntax is not right. Python uses snake_case and By uses CONSTANT convention

from selenium import webdriver
from selenium.webdriver.common.by import By

driver.find_element(By.XPATH, "//input[@type='submit' and @value='save']").click()

It's actually suggested to use the individual methods for each By if you don't need to be dynamic:

driver.find_element_by_xpath("//input[@type='submit' and @value='save']").click()

Or css:

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

If that doesn't work, can you post the error traceback you are getting?

Upvotes: 2

PaLaSeul
PaLaSeul

Reputation: 9

Did you try with other parameter than xpath ? I also had some difficulties with selenium, you can try the following line :

driver.findElement(By.tagName("form")).submit()

It's works for me and is useful to validate forms

Upvotes: 0

Related Questions