简体   繁体   中英

How to find out why an element is disabled briefly?

I am writing automation code to click a button on a web page opened in chrome browser. Turns out that the button is loaded onto the DOM quickly, but is not clickable for a few milliseconds. During the disabled time, its not even marked as disabled by the GUI. So, my automation code instantly finds the button & clicks it, but nothing happens.

One reason could be that there is an attribute called "disabled" in the button code during the disabled time. How do I find out that this is indeed the case ?

Are there any other methods to disable a button/element temporarily ? If yes, then please tell me which methods and how i can check which method was used ?

EDIT - Per rorys suggestion I added code to print element html upon page load. There is no disabled attribute in the html. Am I missing something ?

Without seeing the code or previewing the problem itself, it's hard to say.

It could be that the button is getting added to the DOM, but the click event handlers aren't applied immediately, which would make it seem disabled, until they are applied.

It could be there's a disabled attribute temporarily, for which you could test with in your automation code easily enough; even if it's something like console.log(element); to view the HTML of the element in the console.

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = new WebDriverWait(driver, 30)
      .until(ExpectedConditions.elementToBeClickable(By.xpath(xpathString)));
js.executeScript("arguments[0].click()", topic);

JavascriptExecutor executes better than simply using element.click() also, using WebDriverWait and condition elementToBeClickable postpones the execution of the next code for, as shown above, 30 seconds.

This answer may be way past the time when the question was posted but hope it helps.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM