【发布时间】:2020-11-02 10:32:08
【问题描述】:
1.实际上过去 2 天我试图解决这个异常,但它仍然无法正常工作。因此,即使我使用正确的 xpath 但我仍然遇到此异常,请提出可能是什么问题。
- 我在下面使用 xPath
deliveryChannel=//statusdropdown[@id="deliveryChannelField"]//select
对于这个 xpath 我得到了异常,这个 Xpath 我在测试中使用 case (Test(priority = 4))
printStatus = //statusdropdown[@id="releaseStatusDropDown"]//select
这里没有例外
@Test(priority = 4)
public void deliveryChannel() throws InterruptedException {
wait = new WebDriverWait(driver, 10);
String getDeliveryChannel = sftpCon.deliveryChannel("Search Criteria", 0);
//WebElement deliveryChannelDropDown = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(prop.getProperty("deliveryChannel"))));
WebElement deliveryChannelDropDown = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(prop.getProperty("deleverysize"))));
System.out.println("Delevery Channel Text = "+deliveryChannelDropDown.getText());
select = new Select(deliveryChannelDropDown);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
List<WebElement> listSelectApp = select.getOptions();
for (int i = 0; i < listSelectApp.size(); i++) {
String app = listSelectApp.get(i).getText();
if (getDeliveryChannel.contains(app)) {
listSelectApp.get(i).click();
}
}
}
@Test(priority = 5, retryAnalyzer = com.brcc.tool.RetryFailedTestCases.RetryTestCases.class)
public void getPrintStatus() throws InterruptedException {
wait = new WebDriverWait(driver, 10);
String printStatus = sftpCon.deliveryChannel("Search Criteria", 1);
WebElement printStatusDropDown = wait
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(prop.getProperty("printStatus"))));
select = new Select(printStatusDropDown);
List<WebElement> listSelectApp = select.getOptions();
for (int i = 0; i < listSelectApp.size(); i++) {
String app = listSelectApp.get(i).getText();
if (printStatus.contains(app)) {
listSelectApp.get(i).click();
}
}
}
下面是我的 html 元素
<div class="col-md-8">
<statusdropdown id="deliveryChannelField" ng-reflect-selected-status="print" ng-reflect-optional-status="[object Object]" ng-reflect-return-key="delivery_channel_name" ng-reflect-display-key="delivery_channel_description">
<select class="form-control" name="statusDropdown">
<!--bindings={ "ng-reflect-ng-for-of": "[object Object]"
}-->
<option value="print" ng-reflect-value="print">Print</option>
</select>
</statusdropdown>
</div>
【问题讨论】:
-
你能分享你想要交互的特定元素的 html 元素 dom 吗?
-
请检查我是否添加了 html 元素
-
使用 Select 时必须使用带有 select 标签的元素。在 select = new Select(name) 中使用 name="statusDropdown" 元素。
标签: java selenium selenium-webdriver testng