【发布时间】:2014-05-16 00:39:42
【问题描述】:
我有一个包含以下项目的网站:
<input type="text" style="width:230px;" name="email"></input>
和
<input type="password" style="width:230px;" name="password"></input>
使用以下 python 代码尝试设置值(知道用户名和密码已在代码前面设置):
Helper.getElementByxPath(mydriver,'//*[@name="email"]',username);
Helper.getElementByxPath(mydriver,'//*[@type="password"]',password);
而Helper.getElementByxPath定义为:
def getElementByxPath(mydriver,xPath,valueString):
try:
a = mydriver.find_element_by_xpath(xPath);
a.send_keys(valueString);
return 1;
except:
return 0;
我收到以下错误:
Unexpected error: <class 'selenium.common.exceptions.NoSuchElementException'>
Unexpected error: <class 'selenium.common.exceptions.NoSuchElementException'>
我在这里可能做错了什么?用头撞墙。
我是个白痴,我想要的形式被嵌入框架中。在一个框架内。
【问题讨论】:
-
元素可以在
frame或iframe中。如果元素在框架/iframe 中,则可以使用switch_to_frame(IDENTIFIER),其中 IDENTIFIER 是框架名称、框架 web 元素或框架的索引。或者可能是元素加载缓慢或页面完成加载之后。 -
感谢会调查
switch_to_frame