-3

I have a link in my application which gets enabled after 60 seconds. I have to verify , that the link only gets enabled after 60 seconds not before that. Have tried below ways:

  1. I have tried element to be clickable() with fluent wait/webdriver wait/thread.sleep and all are returning that element is enabled where as it's actually disabled till 60 seconds.

  2. i have tried getAttribute("disabled")also , it also returns false.

The only difference i can see in the html is the class attribute. When it is disabled , class attribute value has additional text (disabled) added to it.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
P K
  • 1
  • 7
  • Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a *specific problem or error and the shortest code necessary* to reproduce it **in the question itself**. Questions without a **clear problem statement** are not useful to other readers. See: [mcve]. – JeffC May 24 '19 at 18:05
  • I think the question is pretty much clear. Can't share the code as it is internal to the organisation i am working for. – P K May 24 '19 at 18:15
  • It may be clear in your mind since you have seen the site and the code but from our perspective it's not clear at all. You haven't described the scenario clearly, you have posted no code, and you haven't even posted the full error/exception message. I'm not sure how we are supposed to be able to help you. For something like this you need to post an [mcve]. Find a demo site that is something like what you have internally and write code against it. – JeffC May 25 '19 at 16:02
  • Please provide some code and some example markup/a link to the site. The main question is how is it disabled, using the disabled attribute, CSS, JavaScript? – Ardesco May 31 '19 at 10:15

2 Answers2

1

Try with this (and tweek as needed):

long ts1 = System.currentTimeMillis()/1000;
new WebDriverWait(driver, 60).until(ExpectedConditions.attributeToBe(element, "disabled", null);
long ts2 = System.currentTimeMillis()/1000;
Assert.assertTrue((ts2-ts1)>=60);

If the element becomes not disabled before 60 seconds is up, assert will fail.

Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
0

As the link within the application gets enabled after 60 seconds and till then (being disabled) the class attribute contains the additional value disabled, to validate this usecase you can use a try-catch{} block and you can use either of the following Python based Locator Strategies:

  • CSS_SELECTOR:

    try:
        WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "tag_name[some_attribute='value_of_some_attribute']:not(.disabled)")))
        print("Class attribute failed to contain the value disabled for 60 seconds")
    except TimeoutException:
        print("Class attribute successfully contained the value disabled for 60 seconds")
    
  • XPATH:

    try:
        WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//tag_name[@some_attribute='value_of_some_attribute' and not(@class='disabled')]")))
        print("Class attribute failed to contain the value disabled for 60 seconds")
    except TimeoutException:
        print("Class attribute successfully contained the value disabled for 60 seconds")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352