我正在尝试从下拉菜单中选择该选项。但它没有被选中。测试用例通过,没有任何错误,也没有选择该选项。因为它是 HTML 下拉菜单,所以我使用了 click。我尝试选择课程,但没有成功。该网站是https://demoqa.com/automation-practice-form/ 我在这里写的代码是
> JavascriptExecutor js=(JavascriptExecutor)driver;
> Actions act=new Actions(driver);
> js.executeScript("window.scrollBy(0,500)");
> WebElement we=driver.findElement(By.xpath("//div[@id='state']"));
> act.moveToElement(we).click().build().perform();
> WebElement we3=driver.findElement(By.xpath("//div[contains(.,'Uttar
> Pradesh')]/following-sibling::div/descendant::input"));
act.moveToElement(we3).click(we3).build().perform();
请求您的帮助。谢谢
发送密钥为“北方邦”后,您需要单击它的不同元素
使用以下代码
new WebDriverWait(driver , 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='react-select-3-input']"))).sendKeys("Uttar");
new WebDriverWait(driver ,20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[contains(@id,'react-select')]"))).click();
下面的代码对我有用。
WebDriver Driver = new ChromeDriver();
Driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String url = "https://demoqa.com/automation-practice-form";
Driver.get(url);
WebElement products=Driver.findElement(By.xpath("//input[@id='react-select-3-input']"));
products.sendKeys("Uttar Pradesh");
products.sendKeys(Keys.ARROW_DOWN);
products.sendKeys(Keys.ENTER);
System.out.println("completed");
driver.findElement(By.xpath("//div[contains(text(),'选择状态')]")).click(); driver.findElement(By.xpath("//input[@id='react-select-3-input']")).sendKeys("NCR", Keys.TAB);