如何使用SeleniumWebDriver(eclipse)单击下拉菜单(不是由select创建的)?
我试图在下一页的“付款方式”下拉列表中选择一个值 登录到 重定向到>>单击“新订单”按钮 在此页面上,有“付款方式”下拉列表。我想为该下拉列表选择“支票”值 我尝试使用链接文本、XPath、选择和操作进行选择。但是,它们都没有起作用如何使用SeleniumWebDriver(eclipse)单击下拉菜单(不是由select创建的)?,selenium,testing,selenium-webdriver,automated-tests,qa,Selenium,Testing,Selenium Webdriver,Automated Tests,Qa,我试图在下一页的“付款方式”下拉列表中选择一个值 登录到 重定向到>>单击“新订单”按钮 在此页面上,有“付款方式”下拉列表。我想为该下拉列表选择“支票”值 我尝试使用链接文本、XPath、选择和操作进行选择。但是,它们都没有起作用 Actions a = new Actions(driver); WebElement b = driver.findElement(By.xpath("//[@id=\"footerAction\"]/span")); a.moveToElement(b).cli
Actions a = new Actions(driver);
WebElement b = driver.findElement(By.xpath("//[@id=\"footerAction\"]/span"));
a.moveToElement(b).click().perform();
使用以下代码:
WebDriverWait wait =new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[normalize-space()='Payment Method']//following-sibling::div")));
driver.findElement(By.xpath("//label[normalize-space()='Payment Method']//following-sibling::div")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='PaymentMethod']//div[@id='footerAction']")));
List<WebElement>options= driver.findElements(By.xpath("//div[@id='PaymentMethod']//div[@id='footerAction']"));
for (WebElement option : options){
if (option.getText().equals("Cheque")){
option.click();
break;
}
}
WebDriverWait wait=newwebdriverwait(驱动程序,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(//label[normalize-space()='Payment Method']//following sibling::div));
findElement(By.xpath(//label[normalize-space()='Payment Method']//following sibling::div”)。单击();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//div[@id='PaymentMethod']//div[@id='footerAction']);
Listoptions=driver.findElements(By.xpath(“//div[@id='PaymentMethod']//div[@id='footerAction']);
用于(WebElement选项:选项){
if(option.getText().equals(“支票”)){
选项。单击();
打破
}
}
使用以下代码:
WebDriverWait wait =new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[normalize-space()='Payment Method']//following-sibling::div")));
driver.findElement(By.xpath("//label[normalize-space()='Payment Method']//following-sibling::div")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@id='PaymentMethod']//div[@id='footerAction']")));
List<WebElement>options= driver.findElements(By.xpath("//div[@id='PaymentMethod']//div[@id='footerAction']"));
for (WebElement option : options){
if (option.getText().equals("Cheque")){
option.click();
break;
}
}
WebDriverWait wait=newwebdriverwait(驱动程序,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(//label[normalize-space()='Payment Method']//following sibling::div));
findElement(By.xpath(//label[normalize-space()='Payment Method']//following sibling::div”)。单击();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//div[@id='PaymentMethod']//div[@id='footerAction']);
Listoptions=driver.findElements(By.xpath(“//div[@id='PaymentMethod']//div[@id='footerAction']);
用于(WebElement选项:选项){
if(option.getText().equals(“支票”)){
选项。单击();
打破
}
}
我们可以获得登录示例吗?所以我可以检查。@Ashokkumarganesen您发布的评论是关于使用Select创建的下拉列表的。但是,此下拉列表不是使用select创建的。因此,我无法选择该值。我已经试过了。但是,它不起作用。你能粘贴你的脚本和网页吗?这是得到你答案的最简单的方法。@nu1silva由于保密性,我不能提供给你。但是,你可以使用这个链接注册。我们可以得到一个登录示例吗?所以我可以检查。@Ashokkumarganesen您发布的评论是关于使用Select创建的下拉列表的。但是,此下拉列表不是使用select创建的。因此,我无法选择该值。我已经试过了。但是,它不起作用。你能粘贴你的脚本和网页吗?这是得到你答案的最简单的方法。@nu1silva由于保密性,我不能提供给你。但是,你可以使用这个链接注册。