я попробую ваш url попозже (на работу надо идти) - вот как - из
https://github.com/s...SuvianTest.java
@Test(enabled = true)
public void test18_2() {
// Arrange
driver.get("http://suvian.in/sel...ressBar.html");
WebElement button1 = wait.until(
ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(
".container .row .intro-message button:nth-of-type(1)"))));
assertThat(button1, notNullValue());
assertThat(button1.getAttribute("disabled"), nullValue());
WebElement button2 = wait.until(
ExpectedConditions.visibilityOf(driver.findElement(By.id("button2"))));
assertThat(button2, notNullValue());
assertThat(button2.getAttribute("disabled"), notNullValue());
WebElement progressBar = wait.until(
ExpectedConditions.visibilityOf(driver.findElement(By.id("myBar"))));
assertThat(progressBar, notNullValue());
assertThat(progressBar.getAttribute("style"), notNullValue());
WebElement progressBarContainer = progressBar.findElement(By.xpath(".."));
int denom = Integer.parseInt(
styleOfElement(progressBarContainer, "width").replace("px", ""));
// Act
button1.click();
// Evaluate the progressBar width to reach 100% - need a longer wait timeout
try {
(new WebDriverWait(driver, 60)).until(new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver d) {
Pattern p = Pattern.compile("([0-9.]+)px",
Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
float percentage = Float.parseFloat(
p.matcher(styleOfElement(progressBar, "width")).replaceAll("$1"))
/ denom;
System.err.println("Progress Bar: " + percentage);
return (percentage >= .97);
}
});
} catch (Exception e) {
System.err.println("Exception: " + e.toString());
}
// Assert
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
System.err.println(
"Button2 attribute check (1) : " + button2.getAttribute("outerHTML"));
button2.click();
try {
// confirm alert
driver.switchTo().alert().accept();
} catch (NoAlertPresentException e) {
// Alert not present - ignore
} catch (WebDriverException e) {
System.err
.println("Alert was not handled : " + e.getStackTrace().toString());
return;
}
// NOTE: latency
System.err.println(
"Button2 attribute check (2) : " + button2.getAttribute("outerHTML"));
}
private String styleOfElement(WebElement element, Object... arguments) {
String getStyleScript = getScriptContent("getStyle.js");
return (String) executeScript(getStyleScript, element, arguments);
}
сам скрипт - из
http://www.htmlgoodi...id=88eQV8NzD6Q
https://developer.mo...etComputedStyle
getStyle = function(element, property) {
var result = '';
if (window.getComputedStyle) {
var styleObj = window.getComputedStyle(element, null);
// var styleObj = document.defaultView.getComputedStyle(element, null);
if (undefined != property ) {
result = styleObj.getPropertyValue(property);
} else {
var len = styleObj.length;
for (var i = 0; i < len; i++) {
var style = styleObj[i];
result += ' ' + style + ':' + styleObj.getPropertyValue(style) + '\n';
}
}
}
// IE lacks getComputedStyle but has currentStyle
else if (element.currentStyle) {
try {
result = element.currentStyle[property];
} catch (e) {}
}
return result;
}
var element = arguments[0];
var property = arguments[1];
return getStyle(element, property);