繁体   English   中英

Selenium Webdriver Python找不到按钮

[英]Selenium webdriver python cannot find button

我尝试在填写表单后找到保存按钮,但是失败了,我尝试使用xpath和classname,css选择器...但是它们都不起作用。 奇怪的是,如果我仅在测试按钮时编写了一个不同的测试,但是在填写表单后却没有(表单本身和按钮在同一个表单标签下)。 这是我的代码:

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()

按钮的xpath: /html/body/main/section/fieldset[1]/div[2]/div[2]/form/div[2]/button[1]

知道为什么硒找不到吗? 请给我一个解决方案?

尝试使用下面的代码,让我们看看t是否适合您-

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

更新

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)

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