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();           
    }
}

最佳答案

选择From(例如Guwahati(GAU)),To(例如Goa(GOI)) url https://spicejet.com/ 中的目的地和DEPART DATE 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/53039454/

相关文章:

java 正则表达式 : capture multiline sequence between tokens

java - 在 java 中创建 Zip 文件而不使用 byte[]

java - 为 Java 定制 --module-path

java - 将 Jsoup "Element"转换为 WebDriver "WebElement"?

java - 模式中前两个字段的 key 未发送

Java:什么是基于索引的数组访问,为什么它们很快?

jsf - 如何在我的 JSF 项目中进行 Selenium 测试?

c# - 在 C# 中将 Httpheader 添加到 selenium chrome webdriver

java - Selenium (2.29.1) 悬停在 Firefox (18.01) 下

java - 重新加载页面,但保留 DOM 保存