I had this HTML output (Firebug):
<a class="tab-toolbar-button tab-widget tab-disabled" title = "Revert All">
<span clas = "tab-toolbar-button-icon tab-icon-revert"></span>
</a>
But after upgrading server and new interface I have this:
<div class="tabToolbarButton tab-widget disabled">
<span class="tabToolbarButtonImg tab-icon-revert"></span>
<span class="tabToolbarButtonText">Revert</span>
</div>
My Java code was:
private static void doResetFilter() throws Exception {
waitForLoadingSpinner();
element =wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(@class, 'tab-toolbar-button')][@title='Revert All']")));
boolean isEnabled = element.getAttribute("class").contains("tab-enabled");
if (isEnabled) {
log("reset filter");
element.click();
}
else {
log("filter reset not needed");
}
}
Now I need to modify my Java code to be compatible with new version. Cause I am new with Selenium and Java (I inherited this code), how can I change part with text?
I have tried like this but still there is no result. Can anyone help?
private static void doResetFilter() throws Exception {
waitForLoadingSpinner();
element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//span[@class=’Revert’]")));
boolean isEnabled = element.getAttribute("class").contains("enabled");
if (isEnabled) {
log("reset filter");
element.click();
}
else {
log("filter reset not needed");
}
}
Thanks upfront!
您可以使用所需的@class
具有所需文本的span
@class
的div
元素:
//div[contains(@class, 'tabToolbarButton') and span = 'Revert']
if u want the element which text is "Revert" use the below code:
element = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.tabToolbarButton.tab-widget.disabled>span.tabToolbarButtonText")));
one more thing, in your new html, there is no class in span that contains
enabled
one div contains disabled.
So let me know this helps or not or you need other thing.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.