【发布时间】:2017-07-24 05:24:57
【问题描述】:
这是一个众所周知的bug,通常它有三种方法来避免它:检查重叠,设置睡眠时间以完全下载页面,检查元素的可见性。 我尝试了所有这些,但它们都不起作用。 好吧: 我正在使用 twitter 页面 https://api.twitter.com/oauth/authenticate?oauth_token=3b8ougAAAAAABl35AAABWpZgqDA 文本字段具有 HTML:
<label for="username_or_email" tabindex="-1">Username or email</label>
<input aria-required="true" autocapitalize="off" autocorrect="off" autofocus="autofocus" class="text" id="username_or_email" name="session[username_or_email]" type="text" value="">
我试过代码:
def input_label:
links = get_driver().find_elements_by_xpath("//label[@for='username_or_email']")
if links:
links[0].send_keys(str(UserName))
else:
raise ValueError('Field with label for username_or_email not found')
我绑了代码:
def input_id:
links = get_driver().find_elements_by_xpath("//input[@id='username_or_email']")
if links:
links[0].send_keys(str(UserName))
else:
raise ValueError('Field with id username_or_email not found')
我尝试在 send_keys 之前单击此 elemnt,但没有尝试。但是我所有的解决方案都不起作用。我总是收到一条错误消息“元素无法点击...”。 有什么建议吗?
【问题讨论】:
标签: python google-chrome selenium xpath