简体   繁体   中英

Selenium webdriver python cannot find button

I tried to locate the save button after filling a form but it failed, I tried with xpath and classname, css selector...but neither of them worked. Strange is that if I wrote a different test when only testing the button it worked, but after filling the form it didn't (the form itself and the buttons are under the same form tag). This is my code:

wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "div.btn-group.form-buttons > button[name=\"save\"]")))

driver.find_element_by_css_selector("div.btn-group.form-buttons > button[name=\"save\"]").click()

The xpath of the button: /html/body/main/section/fieldset[1]/div[2]/div[2]/form/div[2]/button[1]

Any idea why selenium can't find it? Please give me a solution?

Try with below code and lets see if t works for you-

element = driver.find_element_by_css_selector("div.btn-group.form-buttons > button[name=\"save\"]")
driver.execute_script("arguments[0].click();", element)

update

element = driver.find_element_by_css_selector("button.btn.btn-alert.btn-gradient.btn-save-form:first-child")
driver.execute_script("arguments[0].click();", element)

update 2

element = driver.find_element_by_css_selector("button[type='submit'][name='save'][data-speech='Create']")
driver.execute_script("arguments[0].click();", element)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM