元素没有被点击,即使它从硒网络驱动程序的下拉列表中得到了验证



我试图从列表中选择元素。使用下面的代码,它可以找出正确的元素。但它不会单击该元素。不知道如何继续。

网页代码

<div id="__test0-defaultXML--idQueueName" data-sap-ui="__test0-defaultXML--idQueueName" style="width: 100%; max-width: 100%;" class="sapMSlt sapMSltDefault sapMSltHoverable sapMSltMinWidth sapMSltWithArrow" aria-labelledby="__label7 __test0-defaultXML--idQueueName-label" role="combobox" aria-disabled="false" aria-expanded="false" tabindex="0">
<input id="__test0-defaultXML--idQueueName-hiddenInput" aria-multiline="false" aria-readonly="true" tabindex="-1" class="sapUiPseudoInvisibleText">
<label id="__test0-defaultXML--idQueueName-label" for="__test0-defaultXML--idQueueName" class="sapMSltLabel" aria-live="polite">- Select -</label>
<span id="__test0-defaultXML--idQueueName-arrow" class="sapMSltArrow"></span>
<ul style="width:100%;max-width:100%" class="sapMSelectList" role="listbox">
<li tabindex="0" class="sapMSelectListItem sapMSelectListItemBase sapMSelectListItemBaseHoverable sapMSelectListItemBaseSelected" role="option" aria-selected="true" aria-setsize="4" aria-posinset="1">- Select -</li>
<li tabindex="0" class="sapMSelectListItem sapMSelectListItemBase sapMSelectListItemBaseHoverable" role="option" aria-selected="false" aria-setsize="4" aria-posinset="2">sap/smtest/test/a1</li>
<li tabindex="0" class="sapMSelectListItem sapMSelectListItemBase sapMSelectListItemBaseHoverable" role="option" aria-selected="false" aria-setsize="4" aria-posinset="3">sap/smtest/test/test</li>
<li tabindex="0" class="sapMSelectListItem sapMSelectListItemBase sapMSelectListItemBaseHoverable" role="option" aria-selected="false" aria-setsize="4" aria-posinset="4">sap/smtest/test/tt</li>
</ul>
</div>

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
public boolean selectn() {
boolean result = false;
int attempts = 0;
while(attempts < 1) {
try {
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement list1 = driver.findElement(By.xpath("//*[@id="__test0-defaultXML--idQueueName"]/ul"));
list1.click();
List<WebElement> Listnw = list1.findElements(By.tagName("li"));
for(WebElement li : Listnw) {
if (li.getText().equals("sap/smtest/test/a1")) {
li.click();
}
}
result = true;
break;
} catch(StaleElementReferenceException e){
}
attempts++;
}
return result;
} 

WebElement list1 = driver.findElement(By.xpath("//*[@id="__test0-defaultXML--idQueueName"]/ul"));之后。 请添加list1.click();,看看它是否有效。 将下面的代码保留原样。

相关内容

  • 没有找到相关文章

最新更新