我正在尝试从 日历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/
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(); } }