I'm having some problems trying to run a test with selenium webdriver when an Iframe is present on the code.
There is a single Iframe inside the webpage with that I'm working:
<div class="bwc layout">
<div class="bwc-frame">
<iframe id="bwc-frame" class="bwc-frame" src="index.php?module=Campaigns&action=EditView&return_module=Campaigns&return_action=index&bwcFrame=1">
(...)
</iframe>
</div>
</div>
But, when i try to find an element inside of that frame i get this error message:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"name"}
If i use Selenium IDE i haven't problems finding that element. It happens only with webdriver.
This is my (selenium) code:
WebDriver drive = new FirefoxDriver();
driver.get(myUrl);
WebDriverWait wait = new WebDriverWait(driver, 20);
//Login in my site
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("username")));
driver.findElement(By.name("username")).sendKeys("username");
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.name("login_button")).click();
//end of Login (everything is ok with this part, no Iframes inside)
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); //For Web Loading
driver.switchTo().frame(0); //There is a single Iframe
driver.findElement(By.id("name")); //Webdriver can't find this element
I tried to switch to frame in many different ways:
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe.bwc-frame")));
or
driver.switchTo().frame("bwc-frame");
However I'm getting the same result.
I also tried an explicit wait instead of implicit wait:
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("iframe.bwc-frame")));
and i get the same result, NoSuchElementException when i try to find the element inside of Iframe.
Please, anyone have any idea why this is failing ? Thanks.
Aucun commentaire:
Enregistrer un commentaire