【问题标题】:Selenium Drop Down Selection In https://www.goibibo.com/hotels/ website硒下拉选择在 https://www.goibibo.com/hotels/ 网站
【发布时间】:2021-10-08 00:36:32
【问题描述】:

https://www.goibibo.com/hotels/ Image

我想使用 selenium 选择一个城市,但它不起作用 我尝试过使用 xpath、css 选择器、id、className。\

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Goibibo {
    
    public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver_2\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
     //Goto Url Goibibo.com
     driver.get("https://www.goibibo.com/hotels/");
     System.out.println("WWW.GOIBIBO.COM");
     
     //Select Country India
     driver.findElement(By.xpath("//input[@name='CountryType']")).click();

     System.out.println("Selected Country India");
     // Click on Search Bar
     driver.findElement(By.id("downshift-1-input")).click();

     System.out.println("Clicked On Search Bar");

     //Select Mysore City
     driver.findElement(By.xpath("//*[@id=\"downshift-1-menu\"]/div/ul/li[2]/img")).click();;
     }
}

【问题讨论】:

    标签: selenium selenium-webdriver css-selectors selenium-chromedriver dropdown


    【解决方案1】:

    你可以试试下面的xpath:

    //p[text()='Mysore']
    

    //img[contains(@alt,'Mysore')]/following-sibling::div
    

    代码中:

    System.out.println("Clicked On Search Bar");
    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//p[text()='Mysore']"))).click();
    System.out.println("Task has been done !");
    

    【讨论】:

      猜你喜欢
      • 2020-10-31
      • 1970-01-01
      • 2017-05-10
      • 2020-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      相关资源
      最近更新 更多