Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
674 views
in Technique[技术] by (71.8m points)

ajax - Selenium WebDriver - determine if element is clickable (i.e. not obscured by dojo modal lightbox)

I write automated scripts for testing web applications that are very heavy on ajax. For example, a modal dialog is displayed with the text "Saving..." when saving settings, while a lightbox greys out the rest of the page.

My test scripts are trying to click the next link in the test before the message disappears. It almost always works when driving Firefox, but when driving Chrome the following error is displayed:

Exception in thread "main" org.openqa.selenium.WebDriverException: Element is not clickable at point (99.5, 118.5). Other element would receive the click: <div class="dijitDialogUnderlay _underlay" dojoattachpoint="node" id="lfn10Dijit_freedom_widget_common_environment_Dialog_8_underlay" style="width: 1034px; height: 1025px; "></div> (WARNING: The server did not provide any stacktrace information)

This happens because the lightbox is obscuring the element I want to click on. I want to wait for the lightbox to disappear before attempting to click the link.

Checking for the lightbox to no longer exist is not a valid workaround because there are, at times, multiple levels of modal dialogs and lightboxes, and no easy way to distinguish between them.

Is there a way in Selenium to detect if the element is clickable (no other elements obscuring it)? A try/catch would be a workaround, but I'd prefer to do a proper check if that is possible.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use the WebDriverWait conditions.

    WebDriverWait wait = new WebDriverWait(yourWebDriver, 5);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//xpath_to_element")));

Webdriver will wait for 5 seconds for your element to be able to be clicked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...