0 votes
1 view
in DevOps and Agile by (19.8k points)

I have a GWT application for which I'm trying to write some tests using Selenium.

I'm using XPath to identify the elements on the page for the tests. Using ID won't work as the ID values are auto-generated by GWT and can change. Things started going well when I realized I could find buttons by their labels as follows:


However, when I started running multiple tests I started having problems. I realized that the issue was all the different "pages" of the GWT app once generated by the Javascript remain in the HTML in hidden <div> elements. This meant my Selenium tests were sometimes clicking hidden buttons instead of the button visible in the current view.

Examining the HTML with Firebug, it seems that GWT hides the <div> elements by adding display: none to their style attribute. This means I can find all the hidden OK buttons as follows:

//div[contains(@style,'display: none')]//button[.='OK']

This will find all the hidden OK buttons, i.e the buttons which have an ancestor <div> which is hidden by having display: none in the style.

My question is: how do I use XPath to find only the visible OK buttons? How do I find the buttons which have no ancestor <div> elements with display: none in the style?

1 Answer

0 votes
by (63.4k points)

Selenium 2 Webdriver gives us the option of the isDisplayed() method which deals with this problem.


Welcome to Intellipaat Community. Get your technical queries answered by top developers !