I am writing a Selenium Webdriver script that is supposed to click on a Link and then this Modal Window pops up.
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"}
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?
We may encounter the error - unable to locate element while working with Selenium webdriver. This leads to NoSuchElementException. This type of exception is thrown when there is no element on the page which matches with the locator value. Check if there is any syntax error in our xpath expression.
selenium. NoSuchElementException occurs when WebDriver is unable to find and locate elements. Usually, this happens when tester writes incorrect element bin the findElement(By, by) method. This exception is thrown even if the element is not loaded.
ContextClick() Right-clicks the mouse at the last known mouse coordinates.
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With