Reputation: 63
Can someone please help me figure out how to get Selenium Webdriver to find the frame after selecting Sign in??
https://www.guaranteedrate.com/agent/visitors tap sign in sendkeys to Username
@Test
public void fail() throws InterruptedException {
driver.findElement(By.linkText("Sign In")).click();
driver.switchTo().window("GB_window");
driver.switchTo().frame(0); driver.findElement(By.id("username")).sendKeys("[email protected]");
}
Upvotes: 1
Views: 15556
Reputation: 754
Well if the application works on firefox then simply right click. In the context menu you will first find out if the element is under a frame or not by seeing an option This frame. Once you confirm this then inspect the element. Scroll top slowly in the firebug and you will find the iframe tag under which the element is present. In this manner you will get to know the name. If you want to know the count of all the iframes and their names then use driver.findElements(By.tag("iframe")). This will return the list of webelements which have the tag and then you can iterate one by one and use getAttribute("name"). Note this will return the name only if the iframe actually has a name other wise will return empty.
Upvotes: 0
Reputation: 29669
Can you try this and tell me if it works? I suspect that what you are experiencing is a Firefox-only weirdness and a JavaScriptExecutor will get around it.
public void setEmailAddrOnFieldInSubFrame() {
driver.findElement( By.linkText("Sign In") ).click();
driver.switchTo().window("GB_window");
driver.switchTo().frame(0);
WebElement element = driver.findElement( By.id("username") );
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript( "arguments[0].value='[email protected]';", element );
//cleanup frame position by switching back to previous window
driver.switchTo().defaultContent(); // always do this cleanup just in case
}
Upvotes: 1
Reputation: 2337
Try the below code. It worked for me. There are two frames before you can find Username Element. First frame is GB_frame and the second one doesn't have a any name given in the html source. So i have used index (frame(0)
) for the second one.
@Test
public void fail() throws InterruptedException {
driver.findElement(By.linkText("Sign In")).click();
//switch to frames inside the webpage
driver.switchTo().frame("GB_frame"); //1st frame
driver.switchTo().frame(0); //2nd frame
driver.findElement(By.id("username")).sendKeys("[email protected]");
}
Upvotes: 0
Reputation: 871
I think after clicking on Sign in you are taken to a frame, that is the registration form.
What you are trying is to Switch to a window first (GB_Window).
Try removing Switch to window call and just switch to frame and try your operations
After editing your code, use this
driver.findElement(By.linkText("Sign In")).click();
driver.switchTo().frame(0);
driver.findElement(By.id("username")).sendKeys("[email protected]");
}
Upvotes: 0