【发布时间】:2021-05-31 14:57:55
【问题描述】:
我在 Python 中使用 selenium。该页面有一个带有与之关联的类的按钮。我按类使用了 get 元素,但它失败了。请检查下面的代码
<div class="form-cell">
<button type="submit" class="btn btn-orange">Sign Up</button>
</div>
到目前为止已经尝试了以下...并且每次都出现相同的错误。在实际代码中,前三行被注释,所以请注意。
driver.find_element_by_class_name('btn btn-orange').click()
driver.find_elements_by_class_name('btn btn-orange').click()
driver.find_element_by_xpath('//button[@type="button"]/[@class="btn btn-orange"]').click()
driver.find_element_by_xpath("//button[@type='button']/option[text()='Sign Up']").click()
对于上述所有尝试,这都是相同的错误消息。
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@type='button']/option[text()='Sign Up']"}
(Session info: chrome=91.0.4472.77)
我已设法识别文本框并将某些数据输入其中。但现在我正在尝试提交该数据,但似乎无法抓住按钮来点击它。
感谢您的帮助
【问题讨论】:
-
能否提供网页链接?
标签: python selenium button xpath