我卡在了 TestCase 的一个步骤上。硒网络驱动程序
I got stuck on a Step of TestCase. Selenium Webdriver
我试图在 java 中使用 Selenium WebDriver 自动执行一个测试用例,但我卡在了一个步骤上。我需要找到一个元素并单击它。我尝试通过 id、class、csselector、licktext...来定位它,但没有成功。
这是我做的:
driver.findElement(By.cssSelector("a[href=http://mucs70064.corp.knorr-bremse.com:1080/Windchill/app/#ptc1/site/listUtilities?oid=OR%3Awt.inf.container.ExchangeContainer%3A5&u8=1]")).click();
driver.findElement(By.cssSelector("div[ext\:tree-node-id*='site'][ext\:tree-node-id*='listUtilities'] a")).click();
driver.findElement(By.className("x-tree-node-anchor")).click();
driver.findElement(By.className("x-tree-node-indent")).click();
不幸的是,上述任何一种说法都没有奏效。有谁知道我该如何继续?我拍了一张我的浏览器开发工具显示的照片,但由于我还没有足够的声誉来上传它,您可以在下面的 link.
中看到图像
如果有任何帮助,我将不胜感激!
问候
非常感谢
巴勃罗
我觉得这可能是因为 unselectable
属性的值为 on
。您可以等到属性值发生变化。我看到的其他属性是 hidefocus=on
。
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
WebElement button = driver.findElement(By.xpath("xpath"));
String enabled = button.getAttribute("unselectable");
if(enabled.equals("off"))
return true;
else
return false;
}
});
编辑:
获取所有链接,然后单击最后一个。
List<WebElement> links = driver.findElements(By.className("x-tree-node-anchor"));
links.get(links.size()-1); //this will give you the last link
我试图在 java 中使用 Selenium WebDriver 自动执行一个测试用例,但我卡在了一个步骤上。我需要找到一个元素并单击它。我尝试通过 id、class、csselector、licktext...来定位它,但没有成功。
这是我做的:
driver.findElement(By.cssSelector("a[href=http://mucs70064.corp.knorr-bremse.com:1080/Windchill/app/#ptc1/site/listUtilities?oid=OR%3Awt.inf.container.ExchangeContainer%3A5&u8=1]")).click();
driver.findElement(By.cssSelector("div[ext\:tree-node-id*='site'][ext\:tree-node-id*='listUtilities'] a")).click();
driver.findElement(By.className("x-tree-node-anchor")).click();
driver.findElement(By.className("x-tree-node-indent")).click();
不幸的是,上述任何一种说法都没有奏效。有谁知道我该如何继续?我拍了一张我的浏览器开发工具显示的照片,但由于我还没有足够的声誉来上传它,您可以在下面的 link.
中看到图像如果有任何帮助,我将不胜感激!
问候 非常感谢 巴勃罗
我觉得这可能是因为 unselectable
属性的值为 on
。您可以等到属性值发生变化。我看到的其他属性是 hidefocus=on
。
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
WebElement button = driver.findElement(By.xpath("xpath"));
String enabled = button.getAttribute("unselectable");
if(enabled.equals("off"))
return true;
else
return false;
}
});
编辑:
获取所有链接,然后单击最后一个。
List<WebElement> links = driver.findElements(By.className("x-tree-node-anchor"));
links.get(links.size()-1); //this will give you the last link