1

I have a button that is enabled when I choose a value in a picker.

The html code states that aria-disabled="false" when i pick av value in the picker.

<button id="form:panel:j_idt188" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only btn btn-primary col-md-12 selectContext7" data-aft="selectLevel7" type="submit" onclick="PrimeFaces.ab({s:"form:panel:j_idt188",u:"form:kontekstvelger"});return false;" name="form:panel:j_idt188" role="button" aria-disabled="false"

How can I code that the selenium script should wait for the aria-disabled="false" to be false (It is true when I enter the page and before I have chosen a value in the picker.

From before I have this code to wait for elements:

WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("nyid")));

But how can I write this code above to be waiting for aria-disabled to be false?

Guy
  • 46,488
  • 10
  • 44
  • 88
Magnus Jensen
  • 905
  • 6
  • 36
  • 73
  • Check this http://stackoverflow.com/questions/15237129/webdriverwait-for-an-element-attribute-to-change/15237960#15237960 – Andersson Feb 27 '17 at 09:51

2 Answers2

1

You can use cssSelector to wait for element with specific id and attribute

WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("[id='nyid'][aria-disabled='false']")));
Guy
  • 46,488
  • 10
  • 44
  • 88
  • I did but get the message: org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for all conditions to be valid: presence of element located by: By.id: nyidvalue to be "false". Current value: "null" – Magnus Jensen Feb 27 '17 at 11:31
  • and using firebug during test replay I get the value "true", I do not understand how the value can be "null", meybe the step before did not actually press the picker (the browser shows it does though) – Magnus Jensen Feb 27 '17 at 11:32
  • @MagnusJensen You need to use `By.cssSelector`, not `By.id`. Just copy the code from my answer. – Guy Feb 27 '17 at 11:55
0

Try this:

(new WebDriverWait(driver, 10)).until(ExpectedConditions.and(
        ExpectedConditions.presenceOfElementLocated(By.id("nyid")),
        ExpectedConditions.attributeToBe(By.id("nyid"), "aria-disabled", "false")));
Alex
  • 56
  • 3