输入目的地名称时无法通过或选择下拉列表

时间:2017-01-23 00:42:39

标签: java selenium

我正在尝试自学Selenium,但是我无法弄清楚如何关闭或选择从输入框输入目的地后打开的下拉列表。

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Dropdown {

    public static void main(String[] args) {

        System.setProperty("webdriver.gecko.driver", "C:/Users/Karthik/Desktop/Education/Selenium Short/geckodriver-v0.11.1-win64/geckodriver.exe");

        WebDriver D= new FirefoxDriver ();
            D.get("https://www.kayak.com/flights");
            System.out.println(D.getCurrentUrl());
            D.findElement(By.xpath(".//span[text()='One-way']")).click();
            D.findElement(By.xpath("//*[@name='origin']")).clear();
            D.findElement(By.xpath("//*[@name='origin']")).sendKeys("TPA");
            D.findElement(By.xpath("//*[@name='destination']")).sendKeys("DEL");
            D.findElement(By.xpath(".//span[class()='airportCode']")).click();
            WebElement abc=D.findElement(By.xpath(".//*[@class='ap selected']"));
            Alert Work=D.switchTo().alert();
            Work.accept();
            abc.click();

            D.findElement(By.xpath("//*[.//span[text()='Depart']")).sendKeys("02/21/2017");
    }

}

1 个答案:

答案 0 :(得分:0)

尝试使用:

    D.findElement(By.xpath("//*[@name='destination']")).sendKeys(Keys.ENTER);

之后:

  D.findElement(By.xpath("//*[@name='destination']")).sendKeys("DEL");