无法使用硒中的sendkeys发送卡号
Not able to send card number using sendkeys in selenium
我正在使用 XPath 定位文本框并尝试发送卡号,但我无法这样做。
我遇到错误 org.openqa.selenium.NoSuchElementException
我已经提到了我为此使用的代码,还附上了页面快照以供参考。
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"encryptedCardNumber\"]")).sendKeys("...");
根据给定的 HTML 来源,您可以使用 XPath 作为
//input[@id='encryptedCardNumber' and @aria-label='Card number field']
您可以使用 explicitWait
,因为我看到您在卡号字段前使用 implicitWait
new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='encryptedCardNumber' and @aria-label='Card number field']"))).sendKeys("....");
此外,我认为您可以检查页面上的 Iframe
这可能是上述异常的原因
new WebDriverWait(driver,10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("Iframe")));
付款详情位于 iframe 中。您需要切换到 iframe as
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='targetFrame']")));
我正在使用 XPath 定位文本框并尝试发送卡号,但我无法这样做。
我遇到错误 org.openqa.selenium.NoSuchElementException
我已经提到了我为此使用的代码,还附上了页面快照以供参考。
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id=\"encryptedCardNumber\"]")).sendKeys("...");
根据给定的 HTML 来源,您可以使用 XPath 作为
//input[@id='encryptedCardNumber' and @aria-label='Card number field']
您可以使用 explicitWait
,因为我看到您在卡号字段前使用 implicitWait
new WebDriverWait(driver,10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='encryptedCardNumber' and @aria-label='Card number field']"))).sendKeys("....");
此外,我认为您可以检查页面上的 Iframe
这可能是上述异常的原因
new WebDriverWait(driver,10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("Iframe")));
付款详情位于 iframe 中。您需要切换到 iframe as
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='targetFrame']")));