2

I honestly wanted to find the solution on my own, but after more than twenty hours and hundreds of web pages (and a couple of Selenium books) I have to ask for your help.

The BIG problem: Web app working only in IE8. Firebug Lite not working with it for some reason.

What am I trying to accomplish and issues I encounter:
I have a page with a couple of frames. One of the frames contains a menu. I need to click one of the options to expand it and get access to the entries of the submenu and then I can click on the needed submenu entry. When all this is done, I can get access to different information in the frame on the right. I have tried finding the element by linkText, image id, xpath.

Here is the HTML code for the structure from the IE Developer Tools:

IE8 Developer Tools HTML code

I am going through four pages to get here. As that code is not relevant I will not paste it. The code below shows how I am trying to get the correct Xpath.

List<WebElement> allXpathElem = driver.findElements(By.xpath("//frameset"));
     System.out.println("XPath elements number: " + allXpathElem.size());

for(int i=0; i < allXpathElem.size(); i++)
    System.out.println("XPath element " + (i+1) + ": " + allXpathElem.get(i));

After some fooling around:

driver.switchTo().frame(driver.findElement(By.xpath("//frameset/frame[1]")));

List<WebElement> nextStepElem = driver.findElements(By.xpath("//frameset/frame[1]/div"));
System.out.println("XPath elements number: " + nextStepElem.size());
for(int i=0; i < nextStepElem.size(); i++)
        System.out.println("XPath element " + (i+1) + ": " + nextStepElem.get(i));

No matter what I type after /frame1 returns XPath elements number: 0. Would you be so kind to help me figure out how to find all the XPath elements under a certain entry? For example how do I find out all the elements that can go after the frame1/? ?

My ultimate goal is to go through the whole path so that I can click the submenu link (Client letters for example) and the corresponding content gets displayed in the right side frame. Do I have a better way of doing this than XPath?

Web application interface

Thank you!

indigo
  • 57
  • 1
  • 2
  • 8
  • According to [this page about Selenium, IE8 web driver uses Sizzle](http://www.seleniumhq.org/docs/03_webdriver.jsp#internet-explorer-driver), and they don't support XPath natively. I am not sure how Selenium translates XPath to Sizzle, but it stands to reason that there may be some issues. Do you have the same problem with other web drivers (i.e. Firefox or Chrome)? – Abel Sep 24 '15 at 16:49
  • Also, you can try to get the root of any document, i.e. use the XPath `/*`. If that returns zero elements, you know that XPath is not working, or that the input is not considered a "document". – Abel Sep 24 '15 at 16:51
  • Thanks Abel! Unfortunately I cannot try either Firefox or Chrome as the app is working only in IE8. On your second comment after trying the /* I get : XPath elements number: 1 XPath element 1: [[InternetExplorerDriver: internet explorer on WINDOWS (29e8507f-252e-4ac7-9129-29850e525977)] -> xpath: /*] – indigo Sep 24 '15 at 17:16
  • In that case, try to traverse further, and check the names of the elements. I.e., `/*/*` will return all elements one level deep. Try to get the structure you're under. I assume you know that you have two nested framesets to travel, there must be two `switchTo`'s... ;). – Abel Sep 24 '15 at 17:20
  • @Abel Tried '/*/*'. Got _XPath elements number: **2** XPath element 1: [[InternetExplorerDriver: internet explorer on WINDOWS (3a3d8fba-dfb5-4621-afb0-9bf5c18587f8)] -> xpath: /*/*] XPath element 2: [[InternetExplorerDriver: internet explorer on WINDOWS (3a3d8fba-dfb5-4621-afb0-9bf5c18587f8)] -> **xpath: /*/***]_. And yes I know that I have to `switchTo()`, but how do I figure out which `/*/*` to choose? Or should I use `/*/*[1]`? If we forget about XPath is there another way you could recommend? – indigo Sep 24 '15 at 17:34
  • You can use `name(/*/*[1])` to get the name of the element (and I'm sure there are other ways that your host language supports). I do use Selenium, but never needed it with frames (I thought they had gone extinct by now), so I can only hint. My guess is other methods (CSS3 selectors) will have the same issues. – Abel Sep 24 '15 at 17:40
  • Have you checked this: [How to switch between frames in Selenium WebDriver](http://stackoverflow.com/questions/10879206/how-to-switch-between-frames-in-selenium-webdriver-using-java)? – Abel Sep 24 '15 at 17:43
  • This is a legacy webapp still in intensive use. Not likely to be updated. And yes I did use `switchTo().frame(String s)` in my previous steps (two other pages before I got to this one). Thank you! – indigo Sep 24 '15 at 17:52

1 Answers1

2

Your problem is here:

driver.switchTo().frame(driver.findElement(By.xpath("//frameset/frame[1]")));
List<WebElement> nextStepElem = driver.findElements(By.xpath("//frameset/frame[1]/div"));

After you .switchTo() a frame, you now only look at elements inside of that frame. The second line should be:

List<WebElement> nextStepElem = driver.findElements(By.xpath("//div"));
...

Update: From the screenshot of the HTML (note screenshots of text are not helpful - always provide text as text!) it appears there are two nested frames. You will have to traverse all the frames to get to your element(s):

driver.switchTo().frame(0);  // this puts you inside frame src="english/index.htm"
driver.switchTo().frame(0);  // this puts you inside frame name="menuserverFrame"
List<WebElement> nextStepElem = driver.findElements(By.xpath("//div"));
SiKing
  • 10,003
  • 10
  • 39
  • 90
  • Thanks for your reply! Just tried your suggestion and got **XPath elements number: 0**. I have tried this before. I feel like some visually impaired trying to find his way! Thank you in any case! – indigo Sep 24 '15 at 16:42
  • Thank you! Using your suggestion I managed to get access to the /div(s) - 33 of them ;-) ! I have selected the needed div, clicked on the webelement, the list expanded. So thanks to you I got one step further. Now I have to figure out how to use the /span paired with the /div so I can click on the submenu entry. As the update was useful I will bump your answer up ;-). Thanks again! – indigo Sep 24 '15 at 18:42
  • I figured it out! As your suggestion was the trigger point for finding the final solution ;-) I will mark your answer as the final solution. Many thanks! – indigo Sep 24 '15 at 19:05