gpt4 book ai didi

java - Selenium:- 无法在文本框中写入

转载 作者:行者123 更新时间:2023-12-01 18:34:15 25 4
gpt4 key购买 nike

click 事件工作正常,但 sendKeys 事件不工作。

我的代码是:-

 driver.findElement(By.id("radio-1-4")).click();
jse.executeScript("scroll(0, 500);");
System.out.println("Authority Filter");
driver.findElement(By.xpath("//*[@class=\"filter-label-text\" and text()= 'Authority']")).click();
Thread.sleep(3000);
//driver.findElement(By.xpath("//label[@class=\"control-label\" and @for='tfid-665-0']//parent::div[1]/child::input")).sendKeys("Public Work Department");
WebElement element = driver.findElement(By.id("tfid-602-0"));
element.click();
element.sendKeys("public");

我收到错误:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#tfid\-602\-0"}
(Session info: chrome=79.0.3945.130)

文本框的 HTML 是:-

<div class="form-group form-group-depth-1 form-group-search">
<label for="tfid-664-0" class="control-label">
</label>
<input type="text" placeholder="Search for Authorities" id="tfid-664-0" name="search" class="form-control" value="">
</div>

最佳答案

所需的元素是 Angular元素,因此要找到该元素,您必须为 elementToBeClickable 引发 WebDriverWait,并且您可以使用以下任一 Locator Strategies :

  • css选择器:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.form-group-search>label.control-label[for^='tfid']"))).sendKeys("public");
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='form-control' and @placeholder='Search for Authorities']//preceding::label[1]"))).sendKeys("public");

关于java - Selenium:- 无法在文本框中写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60091623/

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