Reputation: 13
I am trying to automate logging into http://wallethub.com/ using selenium java code. After clicking on Sign in link, a modal popup comes up with an iframe containing username and password fields, however I am not able to find the username field using following selenium code.
WebDriver d = new FirefoxDriver();
d.get("http://wallethub.com/profile/test_insurance_company/");
WebElement signIn = d.findElement(By.linkText("Sign In"));
signIn.click();
WebElement frame = d.findElement(By.tagName("iframe"));
WebDriver.TargetLocator locator = d.switchTo();
WebDriver frameDriver = locator.frame(frame);
WebElement active = locator.activeElement();
frameDriver.findElement(By.id("overlay-username")).sendKeys(user);
My code dies on the last line saying cannot find "overlay-username" field, however I have verified , this field exists in firebug console.
This is on linux.
Any help will be appreciated.
Upvotes: 1
Views: 2032
Reputation: 10961
As @Keikoku assumed you are working with the wrong iframe. There is also GoogleTagManger included in the page. If you check frame.getAttribute("src")
you'll see https://apis.google.com/...
.
You can select the correct IFrame with this selector:
frame = driver.findElement(By.cssSelector("#wh-overlay-frame-inside iframe"));
Upvotes: 1