简体   繁体   English

Selenium Webdriver Python找不到按钮

[英]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. 我尝试在填写表单后找到保存按钮,但是失败了,我尝试使用xpath和classname,css选择器...但是它们都不起作用。 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] 按钮的xpath: /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- 尝试使用下面的代码,让我们看看t是否适合您-

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 更新2

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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