1

I am using WebDriver not to test but to do routine things like find out my account balance.

In doing that, I had some not found elements and I iterate though the windows and was able to log in.

Now that I have logged in, I have used find by id, find by xpath, find by class and the object is not found to get my balance that is on the page (at least I can view it and it is in firebug). I printed out the page source but the page source only has the initial source without javascript modifications.

I tried to get the inner html via javascript of the body and it still gave me the html that you get with page source.

Is it possible that WebDriver is not accessing the DOM?

All the posts that I have seen say you have to wait long enough and I have an implicit wait of 30 seconds. I tend to think it is not a waiting problem.

When I use firebug, I see the elements, that is how I got the xpath. But it can't find it with xpath.

I would even be satisfied if I could just save the source (generated by javascript) into a file where all the elements exist.

I used it with firefox and windows xp sp3.

I loop through iframes with this code

List <WebElement> framesList = driver.findElements(By.xpath("//iframe"));
for(WebElement frame:framesList){
    element = driver.findElement(By.className("account-balance"));
    String et= element.getText();
    System.out.println(et);
}

System.out.println("frames:" + framesList.size());

I get frames:0 it detects no frames.

beatgammit
  • 19,817
  • 19
  • 86
  • 129
Leo
  • 111
  • 7
  • You will need to share the DOM, and how you trying to find the elements. Also there may be an iframe which you are not switching into. – Amey May 10 '13 at 21:14
  • Unfortunately the page is that of my bank and I am afraid I would cause problems if I did. Is there a way for me to get the final generated page rather than the page source? – Leo May 10 '13 at 21:53
  • No, I don't see frames and that is what baffles me. I iterate through the windows and frames and it still can't find the items. yet they are there in fire bug. – Leo May 10 '13 at 22:05
  • I assume that I am looping through all possible windows and frames. Yet the information is hidden from webdriver. – Leo May 10 '13 at 22:09

2 Answers2

1

You need to wrap the .findElement in a try/catch. In a try catch clause, and using a loop, you can reduce the implicit timeout to 5 seconds and you can retry until there is no longer an exception. Maybe you'll get some ideas from my post here.

djangofan
  • 28,471
  • 61
  • 196
  • 289
1

I figured out what my problem was.

The code I used above will NOT work. It is iterating frames but not switching to them.

  1. I was looking for iframes but what the code was looking for was in the second frame. I am not looking for just //frame
  2. I had to switch to the proper frame. To do that I had to find the proper xpath for the frame using firepath.
  3. AND Before switching to a frame, i had to go to defaultcontent first.

That is why it could not find the default content.

It is too bad that selenium ide does not record the needed frame and window switching.

I saw another answer that also talks about this How to switch between frames in Selenium WebDriver using Java

Community
  • 1
  • 1
Leo
  • 111
  • 7
  • 1
    That's basically what I recommended in my answer. Every time you switch into a frame and do something, you need to switch out of it to execute more actions on the main window. I talk about this in a powerpoint I made here: https://docs.google.com/presentation/d/1cuSuEz-p8Al-TwFmASSI0x4Jen3NZWohFoxrLDozjks/edit?usp=sharing – djangofan May 12 '13 at 17:40
  • Wow, great powerpoint. One of the problems I had was I was searching for iframes and NOT frame. I only had frames to deal with. The other issue is that there were nested frames I had to navigate through and with I would switch to them, I had to switch back with defaultcontent. If I did not go to default content before the switch I would get element not found. – Leo May 12 '13 at 18:11
  • Yeah, I think that as long as you are careful about it, that things should work for you. I haven't tested on regular frames before, but I have managed to figure out how to deal with iFrames without any problems. – djangofan May 13 '13 at 15:32