2017-09-27 60 views
-1

從與不從下拉菜單中硒 - 下拉

中的字段,這是我的代碼:

public class MyFirst { 
public static void main(String[] args) { 
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\kunal.bhaskar\\Downloads\\chromedriver.exe"); 

     WebDriver driver = new ChromeDriver(); 
     String baseUrl = "https://www.goindigo.in"; 

     driver.get(baseUrl); 


    driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[1]/input[1]")).clear(); 
    driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[1]/input[1]")).click(); 
    Select from = new Select(driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[1]/input[1]"))); 
    from.selectByVisibleText("Delhi"); 
    driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[2]/input[1]")).click(); 
    Select to = new Select(driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[2]/input[1]"))); 
    to.selectByVisibleText("Patna"); 
    driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[3]/input")).click(); 
    Select adult = new Select(driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[3]/div/div[1]/label[2]/select"))); 
    adult.selectByVisibleText("2"); 
    driver.findElement(By.xpath("//*[@id=\"depart-date\"]")).clear(); 
    driver.findElement(By.xpath("//*[@id=\"depart-date\"]")).sendKeys("18 Oct 2017"); 
    driver.findElement(By.xpath("//*[@id=\"return-date\"]")).clear(); 
    driver.findElement(By.xpath("//*[@id=\"return-date\"]")).sendKeys("28 Oct 2017"); 

    driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/div/div/div/ul/li[2]/div/div[1]")).click(); 
    driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[2]/button")).click(); 

} 
+0

這不是一個下拉 – iamsankalp89

+0

那麼如何從給出的選項 – Kunal

+0

選擇任何一個城市,我會提供ü代碼 – iamsankalp89

回答

0

試試這個代碼,從城市和城市是不是一個下拉所以你不能使用Select類來選擇它。

WebDriver driver=new FirefoxDriver(); 
String baseUrl = "https://www.goindigo.in"; 
driver.manage().window().maximize(); 
driver.get(baseUrl); 

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[1]/input[1]")).clear(); 
driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[1]/input[1]")).click(); 

//Select city from 
driver.findElement(By.xpath("//*[@id='roundWay']/form/div[1]/ul/li[1]/input[1]")).sendKeys("Indore"); 

//Select city to 
    driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[2]/input[1]")).sendKeys("Patna"); 

    //select Adults frm drop down 
    driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[3]/input")).click(); 

    Select adult = new Select(driver.findElement(By.xpath("//*[@id=\"roundWay\"]/form/div[1]/ul/li[3]/div/div[1]/label[2]/select"))); 
    adult.selectByVisibleText("2"); 

    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

//select date of depart 
driver.findElement(By.xpath("//*[@id=\"depart-date\"]")).clear(); 
driver.findElement(By.xpath("//*[@id=\"depart-date\"]")).sendKeys("18 Oct 2017"); 

//select date of return 
driver.findElement(By.xpath("//*[@id=\"return-date\"]")).clear(); 
driver.findElement(By.xpath("//*[@id=\"return-date\"]")).sendKeys("28 Oct 2017"); 

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

//Select Currency 
    Select Currency = new Select(driver.findElement(By.id("ui-id-1"))); 
    Currency.selectByVisibleText("Indian Rupee"); 

    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); 
    driver.findElement(By.xpath(".//*[@id='roundWay']/form/div[2]/button")).click(); 
+0

一堆沒有解釋的代碼不是很有用。如果你的回答包含了你做了什麼改變的描述,那麼你的回答會更好。否則,我們必須將您的代碼與原始的逐行和逐字符進行比較。 –

+0

好吧你高興與它沒有問題:) – iamsankalp89

+0

Kunal它正在爲我工​​作請檢查一次,讓我知道 – iamsankalp89