【发布时间】:2013-08-13 13:29:06
【问题描述】:
我面临一个问题,我无法从下拉列表中选择元素以继续进行。
参考网站的网址是“http://www.rechargeitnow.com/needrecharge.jspx”
我尝试了下面的代码,但没有成功。
//WebDriverWait wait = new WebDriverWait(driver, 10);
//WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));
WebDriverWait wait= new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("opId_div")));
//driver.findElement(By.cssSelector("select[id='operatorid']")).sendKeys("Airtel");;
//driver.findElement(By.linkText("mobile")).sendKeys("Airtel");
//driver.findElement(By.xpath("//*[@id='oprauto']")).click();
//driver.findElement(By.xpath("/html/body/div[2]/div/div[6]/div/div/div/div/div[2]/div/div/div/div/div[2]/select/option[5]")).findElement(By.name("Airtel"));
//operator.selectByIndex(1);
//driver.findElement(By.xpath("//*[@id='oprauto']")).sendKeys("Airtel");
driver.findElement(By.xpath("/html/body/div[2]/div/div[6]/div/div[3]/ul/li[3]/img")).click();
//Select operator=new Select(driver.findElement(By.id("operatorid")));
//operator.getOptions();
//operator.selectByVisibleText("Airtel");
driver.findElement(By.tagName(" mobile no. ")).sendKeys("9001785845");
driver.findElement(By.id("transSubscriptionNoID")).sendKeys("9001457868");
//driver.findElement(By.cssSelector("img[id='btn']")).submit();
//driver.findElement(By.id("btn")).submit();
driver.findElement(By.xpath("//*[@id='btn']"));
【问题讨论】:
-
您能告诉我们您尝试了什么(您的代码)吗?
-
您提到的网站不包含简单的选择下拉菜单,而是一个 ajax 下拉菜单,根据您输入的内容动态加载选项。有一种方法可以处理这个问题。在此之前,您可以分享您的代码吗?
-
@vinay 正如我所说,我是网络驱动程序的新手,所以你能给我这个代码,以便我可以进一步尝试
-
好的,我查看了页面...它不是标准的下拉菜单。但是,您可以单击箭头(打开下拉菜单)而不是
Select代码,然后使用 By.linkText("Airtel") 选择选项。 -
@MrTi T 也试过这个,但它不工作........
标签: java selenium webdriver selenium-webdriver