1

I'm trying to write a Selenium Testcase and started with the Selenium IDE in Firefox. The test is working quite fine there. Now I want to automate that test with Selenium Webdriver and exported the according JAVA class. Everything is setup and working fine so far (the Internet Explorer window is opening, the according page is displayed).

BUT: Selenium Webdriver does not find the element. I want to get the following element:

<div class="x-grid3-cell-inner x-grid3-col-instance/status" unselectable="on">Open</div>

and I have the following code:

    WebElement openWorkItem = driver.findElement(By.xpath("//div[contains(text(),'Open')]"));
System.out.println(openWorkItem.getText());

In the testcase with Selenium IDE the statement is pretty much the same, and it is working:

<td>//div[contains(text(),'Open')]</td>

The only difference is, that the Selenium IDE is only available in Firefox, but in the end I want to have the test executed in IE with Selenium WebDriver.

Any help is very much appreciated.

==Update== I executed driver.getPageSource() and now see that the HTML part I am looking for is not available because it seems to be located in an iFrame. Any ideas?

7
  • tried //div[text()='Open']? Commented Jun 29, 2014 at 10:19
  • thx for the suggestion. I tried it, but it does not work either. Commented Jun 29, 2014 at 10:27
  • does the page use frames? if so, frames are treated differently by browsers, so the first frame could be frame[0] for IE 6,7,8,9 but W3C defines the first as frame[1]. To solve this problem in IE, set the SelectionLanguage to XPath. Commented Jun 29, 2014 at 10:34
  • 1
    stackoverflow.com/questions/7923718/… Commented Jun 29, 2014 at 10:45
  • 2
    "Any ideas?" - Yes, switch to that iframe before you try to find the element. Commented Jun 29, 2014 at 10:50

1 Answer 1

3

You can use findElement to get the frame webelement and have it used with the switchto() method.

driver.switchTo().frame(driver.findElement(By.xpath("iframe[contains(@name=pngNewC‌​ase1143241142570_IFrame)]")));

If you have some other attribute like src, you can try the below.

WebElement frame=driver.findElement(By.xpath("//iframe[@src='showNewClaimForm.action']");
driver.switchTo().frame(frame);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.