当前位置: 首页 > 面试题库 >

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

徐德海
2023-03-14
问题内容

我正在尝试从
日历https://spicejet.com/中选择一个截止日期为2018年10月31日的日期,但我收到了“未知错误:
元素在点(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();           
    }
}

问题答案:

要在URL中选择From(例如Guwahati(GAU)),To(例如Goa(GOI))
目的地和DEPART DATE作为31/10,您需要诱导WebDriverWait以使所需元素可单击,并且可以使用以下解决方案:https://spicejet.com/

  • Code Block:
        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();
        }
    }


 类似资料:
  • HTML与它的外观截图一起粘贴,如下所示。 HTML: 我曾经试过 甚至试图等待命令以使定位器被找到但没有成功。 WebDriverWait(驱动程序,100)。直到(预期条件.element可禁用)(By.css选择器 两者都不起作用,因为它无法识别元素。有人能帮我吗。如果可能,我们甚至可以单击“上一个”和“下一个”,以便我们也可以单击一些以前的日期吗?

  • 我无法从日历中选择数据,因为它没有可选择的id。 下面是我的HTML代码, 我试过的代码是 但无法选择日期 申请的网址: http://demo.guru99.com/V4/ 用户名: mgr123密码: mgr!23 单击左侧窗格中的新帐户,选择上面讨论的所需页面。 有人能帮忙选择日期吗?

  • 问题内容: 问题: 无法从CSS选择器特定元素中选择。需要验证注册用户是否可以成功更改其密码。我试过了类的不同属性来调用它。当尝试前两个示例时,结果是方法中的异常错误。最后的尝试将调用第一个类实例并重置密码字段(失败)。 尝试过: 目的: 我需要选择共享同一班级的项目。如下所示,该类是共享的。 问题答案: 编辑:因为选择器需要一个,或,但是它们本身都不是。 提供要匹配的类名,并从那里指定要选择的特

  • 问题内容: 我试图通过类名选择一个,但是它不起作用,我正在尝试使用它,但是当我尝试在不能的元素中键入内容时,请帮我这是我的代码: 这是我网页中的HTML: 问题答案: 通过xpath找到iFrame解决了问题 然后返回到顶部窗口:

  • 我已经记录了用于从日期选择器中选择日期的selenium代码。在运行测试用例时,日期选择器会弹出并正确突出显示所选日期。但是没有选择日期。代码如下所示:- 此异常仅出现在记录的代码中。我使用的是selenium-server-standalone-2 . 45 . 0 jar。