我正在编写一个 Selenium Webdriver 脚本,该脚本应该单击链接,然后弹出此模态窗口。
当我尝试访问卡号字段(//input[@id=pan])时,出现“找不到此类元素”异常org.openqa.selenium.NoSuchElementException:没有此类元素:无法定位元素: {“方法”:“id”,“选择器”:“平移”}
这是我尝试过但没有成功的代码:
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']"));
也尝试过这个:
WebElement modal = driver.findElement(By.className("ute-pay-now-modalContent"));
driver.switchTo().frame(modal);
WebElement el = driver.findElement(By.xpath("//input[@id='pan']"));
也尝试过这个:
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"));
也尝试过这个:
driver.switchTo().defaultContent();
也尝试过这个:
driver.switchTo().activeElement();
有人可以帮我建议如何解决这个问题吗?
最佳答案
看起来<div class="ute-pay-now-modalContent">
包含iframe#sema
需要 input
field 。尝试下面的代码并让我知道结果:
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"));
关于Selenium Webdriver 无法获取 Modal 中的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42882523/