我正在尝试从日历中选择截至 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(); } }
浏览器快照:
关于java - 无法通过 Selenium 和 Java 在 https ://spicejet. com 中选择出发日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53039454/