[英]Locate an fill input element with selenium python
I'm Trying to fill the next txtBox but I'have tried with the xpath, name, class.我正在尝试填充下一个 txtBox,但我已尝试使用 xpath、名称、类。
<input name="txtNumDoc" type="text" id="txtNumDoc" class="txtBox">
But always get me the same error.但总是让我犯同样的错误。
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[contains(.,'txtNumDoc')]"}
First, the element you are trying to access is inside an iframe so you need to switch to that first:首先,您尝试访问的元素位于 iframe 内,因此您需要先切换到该元素:
iframe = driver.find_element_by_id("iframeBDUA")
driver.switch_to.frame(iframe)
and then you can find your element:然后你可以找到你的元素:
element = driver.find_element_by_id("txtNumDoc")
//*[contains(.,'txtNumDoc')]
is not a valid xpath for this element as we don't have text txtNumDoc
for this element. //*[contains(.,'txtNumDoc')]
不是此元素的有效 xpath,因为我们没有此元素的文本txtNumDoc
。 txtNumDoc
is attribute value for both name and id in this case.在这种情况下,
txtNumDoc
是 name 和 id 的属性值。
use the below.使用下面的。
//input[@id="txtNumDoc"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.