java - 无法通过 Selenium 和 Java 在 https ://spicejet. com 中选择出发日期

标签 java selenium selenium-webdriver xpath webdriverwait

我正在尝试从日历中选择截至 2018 年 10 月 31 日的“出发日期”https://spicejet.com/但我收到错误“未知错误:元素在点 (832, 242) 处不可点击。其他元素将收到点击:...”请帮助我。这是我的代码遇到这样的异常:

public class bookflight extends Thread {

    UtilityMethods utilObj= new UtilityMethods();
    @Test
    public void SighnUp() throws IOException
    {
        utilObj.getdriver().get("https://spicejet.com");
        utilObj.getdriver().manage().window().maximize();

        utilObj.getdriver().findElement(By.id("ctl00_mainContent_ddl_originStation1_CTXT")).click();
        utilObj.getdriver().findElement(By.xpath("//a[contains(text(),'Guwahati (GAU)')]")).click();
        utilObj.getdriver().findElement(By.xpath("//a[contains(text(),'Goa (GOI)')]")).click();
        utilObj.getdriver().findElement(By.className("ui-datepicker-trigger")).click();
        utilObj.getdriver().findElement(By.xpath("//div[@class='ui-datepicker-group ui-datepicker-group-first'])/parent:://table[@class='ui-datepicker-calendar']following-sibling::./a/contains(text(),'31')")).click();           
    }
}

最佳答案

选择出发地(例如古瓦哈提(GAU))、目的地(例如果阿(GOI))您需要在 url https://spicejet.com/ 中将目的地和出发日期设置为 31/10诱导 WebDriverWait 使所需的元素可点击,您可以使用以下解决方案:

  • 代码块:

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    public class spicejet_login {
    
        public static void main(String[] args) {
    
    
            System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
            WebDriver driver = new FirefoxDriver();
            driver.get("https://spicejet.com");
            new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']"))).click();
            driver.findElement(By.xpath("//div[@id='glsctl00_mainContent_ddl_originStation1_CTNR']//table[@id='citydropdown']//li/a[@value='GAU']")).click();
            driver.findElement(By.xpath("//div[@id='ctl00_mainContent_ddl_destinationStation1_CTNR']//table[@id='citydropdown']//li/a[@value='GOI']")).click();
            new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//table[@class='ui-datepicker-calendar']//tr//a[contains(@class,'ui-state-default') and contains(.,'31')]"))).click();
        }
    }
    
  • 浏览器快照:

spicejet_depart_date_31oct2018.png

关于java - 无法通过 Selenium 和 Java 在 https ://spicejet. com 中选择出发日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58622782/

相关文章:

Java Bukkit - 插件无法解析为变量

java - 如何从 NetBeans 运行 Gephi?

java - 微服务之间的通信、共享实体或其他 hell

python - 如何使用当前用户数据远程创建 Python Selenium Chrome webdriver?

java - 如何使用 Maven 通过注释值搜索并运行 TestNG 测试方法?

python - 按索引从下拉列表中选择第一项不起作用。未绑定(bind)方法 select_by_index

ruby-on-rails - 运行 "rails test"会抛出 Bad file descriptor (Errno::EBADF) 错误

java - 使用 NavigationComponent 在另一个 DialogFragment 的 navBackStackEntry 观察者结果中显示 DialogFragment

python - 如果使用 PhantomJS,权限错误

python - 在 python/ruby/perl 中使用 Selenium Webdriver