Reputation: 176
I am trying to write a WebDriver test for the following site for learning purposes: http://www.mate1.com
On clicking the login link, I get a form to fill in my email id and password. As far as I understand, the form is shown in an iframe.
To enter the credentials, I tried to identify the number of iframes for that particular page (and found it as 7) and tried switching in to each iframe and search for the email field by XPath and the ID. However, I wasn't successful to find it. So how can this be done?
This is my code:
driver.get("http:www.mate1.com");
driver.findElement(By.xpath("//*[@id='header-container']/div/a")).click();
List <WebElement> frames = driver.findElements(By.tagName("iframe"));
System.out.println("Totalframes -> "+ frames.size());
driver.switchTo().frame(0);
driver.findElement(By.xpath("//[@id='email']")).sendKeys("[email protected]");
Upvotes: 0
Views: 662
Reputation: 399
The login and password fields are not in an iframe, you can directly use the following code -
driver.findelement(By.id("email").sendKeys("[email protected]");
Try not to switch to any iframe and execute the above line, this will work.
Upvotes: 0
Reputation: 9019
This is likely a good situation to use switchTo().frame(WebElement)
:
driver.switchTo().frame(findElement(By.cssSelector(".iframe-container>iframe")));
Upvotes: 1