rohit12sh
rohit12sh

Reputation: 847

Selenium Webdriver unable to get elements in Modal

I am writing a Selenium Webdriver script that is supposed to click on a Link and then this Modal Window pops up.

Modal Window on the page

When I try to access card number field (//input[@id=pan]), I get No such element found exception org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"pan"}

Input control I want to get hold of

This is the code I have tried with no luck:

WebElement modal = driver.findElement(By.xpath("//div[@class='ute-pay-now-modalContent']"));
driver.switchTo().frame(modal);
WebElement el =  driver.findElement(By.xpath("//input[@id='pan']"));

Also tried this:

WebElement modal = driver.findElement(By.className("ute-pay-now-modalContent"));
driver.switchTo().frame(modal);
WebElement el =  driver.findElement(By.xpath("//input[@id='pan']"));

Also tried this:

WebDriverWait block = new WebDriverWait(driver,10);
WebElement modal = block.until(ExpectedConditions.visibilityOfElementLocated(By.className("ute-pay-now-modalContent")));
WebElement pan;
pan    = modal.findElement(By.id("pan"));

Also tried this:

driver.switchTo().defaultContent();

Also tried this:

driver.switchTo().activeElement();

Can someone please help suggest me how to resolve this issue?

Upvotes: 6

Views: 16841

Answers (1)

Andersson
Andersson

Reputation: 52665

It seem that <div class="ute-pay-‌​now-modalContent"> contains iframe#sema with required input field. Try below code and let me know the result:

WebDriverWait block = new WebDriverWait(driver,10);
block.until(ExpectedConditions.visibilityOfElementLocated(By.className("ute-pay-now-modalContent")));
driver.switchTo().frame("sema");
WebElement pan;
pan = modal.findElement(By.id("pan"));

Upvotes: 6

Related Questions