views:

1900

answers:

4

Hi,

I'm using Selenium RC with chrome-mode for Firefox to automate test cases for a web application. I'm writing the scripts in Java using TestNG framework and Eclipse. Now to the main point:

I'm having problems with Selenium RC for recognizing certain XPaths. I validate my XPaths with XPath-Checker extension for Firefox which shows no error. I then try it out in Selenium IDE to make sure that XPath is being recognized. Even IDE recognizes the element. But its the Selenium RC just doesnt recognize it. Is there anything I can do to correct this?

Specifically, I'm trying to click on a particular area given by:

html/body/form/div[@id='someid1']/div[@class='someClass']/div[@id='someid2']/div[@id='someid3']/div[@id='someid4']/div[@title='titleOfTheElement']

Then I also tried:

//div[@title='titleOfTheElement']
xpath=//div[@title='Automated User']
xpath=/descendant::div[@title='Automated User']

Still nothing!

1) Can someone please suggest what could be wrong, or whether Selenium is known to have problems with XPath?

2) Isn't there any addon (similar to XPath checker) that helps us to see things the way Selenium RC sees? This way we could be sure whether RC is going to recognize the XPaths.

Thanks,
Mugen

Here is the Selenium code:

selenium.click("somelink");
selenium.waitForPageToLoad("30000");

boolean flag=false
  do{
    if (selenium.isTextPresent("Some text on the page which loads last"))
    {
      flag=true
    }
  }while(flag=false);


selenium.click("locator for area which is driving me crazy");

Now at the last step if I were to click anywhere else on the page (meaning some other locator) the click would work.

The HTML for the area looks like this:

<div id="someid1" style="overflow: hidden;">
<div id="someid2" title="title1" class="someclass">title1</div>
<div id="someid3" title="title2" class="someclass">title2</div>
<div id="someid4" title="required title" class="someclass">required title</div>
<div id="someid5" title="title3" class="someclass">title3</div>
<div id="someid6" title="title4" class="someclass">title4</div>
<div id="someid7" title="title5" class="someclass">title5</div></div>

Thanks a load for looking into this. :-)

A: 

Are you sure that the page is loaded correctly with RC, ie do you see the browser open and the page load?

Jeremy French
Thanks for replying Jeremy. Yes, I'm able to see the page open correctly. The XPaths for other areas seem to work fine. Its in one particular area that it just wont recognize at all.Clicking on different elements in this particular area makes some changes to another div in the page. Could this be related to the problem?
Mugen
+4  A: 

I'm not sure if it's correct to have a div with a title attribute. Isn't there another attribute you could use to locate the element?

Anyway, here's the css version of the locator, in case it works:

css=div[title='Automated User']
Santi
Thanks a load for the answer! Using css is working great! I was wrongly trying css as css=div[@title='Automated User'] - silly me!
Mugen
Glad to see it worked :)
Santi
+1  A: 

We had once an issue with XPath expressions when running Selenium tests on Firefox.

  • Have you tried running the same tests with different browser?
  • I remember we replaced all element names with asterisk signs (*) and that helped. i.e.

    //*[@id='someid1']/*[@class='someClass']/*[@id='someid2']

Grzegorz Oledzki
+1  A: 

From your example, you should be able to use the ID of the target element:

selenium.click("id=someid4");

Although I suspect that the IDs are dynamically generated and you are unable to use this method.

I can't see any reason why the following xpath wouldn't work:

selenium.click("//div[@title='required title']");

Other ways to target it would be:

selenium.click("css=div[title='required title']");
selenium.click("css=.someclass:nth-child(4)"); //must be 4th child of parent element

Is the div your actual target element? Does it respond to a click event? If there is a child element that responds to the click then you will need to target that instead. Also, you could try troubleshooting with the following commands:

mouseDown
mouseUp
fireEvent
Dave Hunt