无法在ajax覆盖弹出窗口中单击或发送键,其显示元素不是使用selenium和java的难以处理的异常

oknwwptz  于 2021-06-26  发布在  Java
关注(0)|答案(2)|浏览(364)

我一直在练习为web应用程序way2automation.com自动化一些场景,并努力在弹出的注册表中输入文本。我已经做了一些研究,尝试了下面提到的许多方法:
a) 使用webdriverwait和显式wait b)使用隐式wait和thread.sleep c)使用javascriptexecutor
但他们没有为我工作,我仍然坚持注册用户。非常感谢你的帮助。下面是人工制品
网址:http://way2automation.com/way2auto_jquery/index.php

代码试验:
1)

//  WebElement ele = driver.findElement(By.xpath("//*[@id='load_form']/div/div[2]/input"));
//  JavascriptExecutor executor = (JavascriptExecutor)driver;
//  executor.executeScript("arguments[0].click();", ele);
//  WebElement button = driver.findElement(By.xpath("//*[@id=\"load_form\"]/div/div[2]/input"));
//  new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOf(button));
ercv8c1e

ercv8c1e1#

You need to handle windows
Try the below code and let me know updates

 driver.get("http://way2automation.com/way2auto_jquery/index.php");
        String parent=driver.getWindowHandle();
        String child=driver.getWindowHandle();
        driver).switchTo().window(child);
        driver.findElement(By.name("name")).sendKeys("Abhishek Saxena");
2o7dmzc5

2o7dmzc52#

要单击提交,您可以使用以下任一定位器策略: cssSelector :

driver.findElement(By.cssSelector("input.button[value='Submit']")).click();
``` `xpath` :

driver.findElement(By.xpath("//input[@class='button' and @value='Submit']")).click();

但是,由于元素是一个动态元素,所以 `click()` 在元素上,您需要为 `elementToBeClickable()` 您可以使用以下任一定位器策略: `cssSelector` :

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.button[value='Submit']"))).click();
``` xpath :

new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='button' and @value='Submit']"))).click();

参考

有关nosuchelementexception的详细讨论,请参见:
nosuchelementexception,selenium无法定位元素

相关问题