gpt4 book ai didi

Java selenium 无法发送按键和单击元素

转载 作者:行者123 更新时间:2023-12-02 01:55:49 26 4
gpt4 key购买 nike

我想尝试登录 this website

这是我的代码:

driver.findElement(By.id("userid_sebenarnya")).sendKeys("myUserName");

这是输入文本的属性 id='userid_sebenarnya'

<div class="form-group" id="form-group-height">
<label for="userid" class="text-field-label-horizontal-empty">User ID</label>
<input id="userid" class="fake_field_userid" style="-webkit-box-shadow: inset 0 0 0 2em transparent !important" value="autofill field" type="text">
<div class="outer-border-login">
<input class="form-control-login-transparent" id="userid_sebenarnya" placeholder="Masukkan user ID" onblur="removeErrMsg('#userid');" data-rule-required="true" data-msg-required="Field ini dibutuhkan" autocomplete="off" readonly="" onfocus="this.removeAttribute('readonly'); this.focus();" value="" autocorrect="off" autocapitalize="off" spellcheck="false" maxlength="2147483647" style="-webkit-box-shadow: inset 0 0 0 2em transparent !important" type="text">
</div>
</div>

但是我收到了如下所示的错误消息,而如果我目视查看应该可以找到它。

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"userid_sebenarnya"}

这是否与隐藏文本输入有关,我该怎么办?

最佳答案

  1. 您的网页登录请求位于框架下,因此我们首先需要切换到框架,然后找到元素。

    &lt frameset &gt 
    &lt frame src='/retail3/loginfo/loginRequest' name="mainFrame"
    scrolling="auto" noresize &gt
    &lt/frameset&gt

JAVA代码:

driver.get("the_site");      
driver.switchTo().frame("mainFrame");
driver.findElement(By.id("userid_sebenarnya")).sendKeys("myUserName");
driver.findElement(By.id("pwd_sebenarnya")).sendKeys("myUserName");
driver.findElement(By.id("btnSubmit")).click();
  • 直接使用以下网址登录。它不包含框架:

    This link

  • 关于Java selenium 无法发送按键和单击元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52293144/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com