英文:
dynamic dropdown in selenium
问题
这是我一直在尝试自动化 SpiceJet 航空公司的出发地和目的地字段的代码,但我遇到了一个错误,即无法找到元素,错误信息是 //a[@value='GOI'])[2]
。
有人可以帮助我吗?
此外,如果我继续尝试,就会显示错误,即无法定位起始字段的定位器,尽管之前它是有效的。有人可以解释一下吗?
编程语言:Java
driver.get("https://www.spicejet.com");
driver.findElement(By.xpath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']")).click();
driver.findElement(By.xpath("//a[@text='Amritsar (ATQ)']")).click();
driver.findElement(By.xpath("(//a[@value='GOI'])[2]")).click();
英文:
This is the code with the help of which i have been trying to automate spicejet from and to fields, the error i am getting is unable to find element i.e,, //a[@value='GOI'])[2]
.
can someone please help me?
Also if i keep on trying then it shows the error that the very from field locator is unable to locate, though it worked earlier. can someone please explain this to me?
Lang:java
driver.get("https://www.spicejet.com");
driver.findElement(By.xpath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']")).click();
driver.findElement(By.xpath("//a[@text='Amritsar (ATQ)']")).click();
driver.findElement(By.xpath("(//a[@value='GOI'])[2]")).click();
答案1
得分: 0
你的 xpath 完全没问题。你需要使用一些 WebDriverWait()
并等待 elementToBeClickable()
。
driver.get("https://www.spicejet.com")
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']"))).click()
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[text()='Amritsar (ATQ)']"))).click()
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.xpath("(//a[@value='GOI'])[2]"))).click()
英文:
Your xpath is absolutely fine.You need to induce some WebDriverWait()
and wait for elementToBeClickable()
.
driver.get("https://www.spicejet.com");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']"))).click();
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@text='Amritsar (ATQ)']"))).click();
new WebDriverWait(driver, 5).until(ExpectedConditions.elementToBeClickable(By.xpath("(//a[@value='GOI'])[2]"))).click();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论