您好我正在尝试在列表选项冷和流感上选择但我得到的元素不可见异常,有人可以帮我如何在selenium脚本中选择它。
网站网址:http://www.healthdirect.gov.au/symptom-checker/tool?symptom=COLD
感冒和流感这是我的硒代码
public void selectspecificSymptom(String arg) throws InterruptedException {
// TODO Auto-generated method stub
switch(arg.toLowerCase())
{
case "cold and flu":
/* Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.xpath("//*[@ng-true-value='49|Feeling sick or unwell|1']"));
actions.moveToElement(menuHoverLink);
actions.click();
actions.perform();*/
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@ng-true-value='49|Feeling sick or unwell|1']")).click();
driver.findElement(By.id("submitAnswer"));
break;
default:
System.out.println("Not a valid option");
break;
}
}
答案 0 :(得分:0)
试用此代码:
public class Stack{
@Test public static void select() throws InterruptedException{
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.get("http://www.healthdirect.gov.au/symptom-checker/tool");
//wait for the iframe and switch
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement frame = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[contains(@id, 'easyXDM_default')]")));
driver.switchTo().frame(frame);
Thread.sleep(11000);
//Get all your health topics and select one which matches
List<WebElement> l = driver.findElements(By.xpath("//*[@id='leftCol']/div/button"));
for (int i = 0; i < l.size(); i++) {
System.out.println(l.get(i).getText());
if (l.get(i).getText().equalsIgnoreCase("Ear, nose and throat")){
l.get(i).click();
Thread.sleep(2000);
//Get all your symptoms and select the needed
List<WebElement> l1 = driver.findElements(By.xpath("//*[@id='contentHeight']/div[2]/button"));
//Place your second for loop for the second list here
l1.get(1).click(); //just to test your 'Colds and flu' link
}
}
备注:强>