gpt4 book ai didi

java - 无法单击填充源框后可见的元素

转载 作者:行者123 更新时间:2023-12-02 13:26:47 27 4
gpt4 key购买 nike

当我填写源文本框,然后尝试在搜索特定项目的基础上选择选项时,我无法选择该项目。这是我的代码

driver.get("http://bus.easemytrip.com/");
WebElement src=driver.findElement(By.id("txtSrcCity"));
src.click();
src.sendKeys("agra");
driver.findElement(By.xpath("//li[text()='Agra']")).click();

<div class="bus-from">
<label>From :</label>
<input id="txtSrcCity" class="select-txtn-bus ng-untouched ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required" type="text" placeholder="Source City" name="txtSrcCity" ng-model="search.source" autocomplete="off" ng-change="OnSourceEdit()" required=""/>
<div class="drop" ng-show="sourceDiv">
<ul>
<!-- ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Agra 1 Day Package</li>
<!-- end ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Agra</li>
<!-- end ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Agra 1 Day Tour</li>
<!-- end ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Agra Fort</li>
<!-- end ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Jaipur Agra Mathura Tour</li>
<!-- end ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Jaipur Ajmer Agra Tour</li>
<!-- end ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Agra Cantt Railway Station</li>
<!-- end ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Agra I.s.b.t</li>
<!-- end ngRepeat: src in sourceCity -->
<li class="ng-binding ng-scope" ng-click="SetSource(src.id,src.name)" ng-repeat="src in sourceCity">Agrahar</li>
<!-- end ngRepeat: src in sourceCity -->
</ul>
</div>
</div>

最佳答案

下拉菜单需要一些时间才能显示。您可以将显式等待Expected Conditions一起使用等待它可见

driver.get("http://bus.easemytrip.com/");
WebElement src=driver.findElement(By.id("txtSrcCity"));
src.click();
src.sendKeys("agra");

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement option = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[text()='Agra']")));
option.click();

关于java - 无法单击填充源框后可见的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43368447/

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