I'm using Java to create selenium test cases. My system is based on portlets connected to each other. I'm using "selectFrame" command to select the portlet.
I tried many things but it seems it is not working like this:
driver.switchTo().frame("//iframe[contains(@src,'FUN_UnitList_FilterByLevelIndexOne')]");
driver.findElement(By.id("//iframe[contains(@src,'FUN_UnitList_FilterByLevelIndexOne')]"));
Can anyone help me?
You have an XPath expression that is supposed to get you the IFrame element you need. However you are not telling Selenium it's an XPath expression. The below is what you need:
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'FUN_UnitList_FilterByLevelIndexOne')]"));
Note, my Java is not it's best, so this may cause compilation issues but you should see the idea.
Find the element first, by telling Selenium it's an XPath expression you are giving it, then use that element and stick it right in the 'switch to frame' expression.
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(@src,'FUN_UnitList_FilterByLevelIndexOne')]")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With