元素在点处不可单击。铬。网络驱动程序。Python

2024-04-23 22:34:25 发布

您现在位置:Python中文网/ 问答频道 /正文

它已经是众所周知的错误,通常有三种方法来避免它:检查重叠、设置睡眠时间以完全下载页面、检查元素是否可见。 我都试过了,但都不管用。 好: 我在使用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="">

我试过密码:

^{pr2}$

我把代码绑在一起:

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

我试过在发送密钥之前点击这个元素,没有。但我所有的解决办法都不管用。我总是收到一条错误消息“元素在点上不可点击…”。 有什么建议吗?在


Tags: ortextid元素inputemail错误username
1条回答
网友
1楼 · 发布于 2024-04-23 22:34:25

你的第一次尝试是向标签发送文本。你的第二次尝试是正确的。但是,input元素没有id属性。将id更改为name,然后将links[0].send_keys()更改为{}:

def input_id:
   links = get_driver().find_elements_by_xpath("//input[@name='username_or_email']")
    if links:
        links[1].send_keys(str(UserName))
    else:
        raise ValueError('Field with id username_or_email not found')

编辑:为了澄清一下,我看到你发布的HTML中有一个id属性,但在我能找到的Twitter登录元素中却没有这个属性。在

编辑2:如果问题与脚本尝试填充凭据之前未完全加载元素有关,请尝试使用WebDriverWait。例如:

^{pr2}$

相关问题 更多 >