问题描述
如何处理该网站"https://www.goibibo .com/"中添加硒.请帮助
how handle auto suggest in "from" and "destination" box for this website "https://www.goibibo.com/" in selenium.please help
我已经厌倦了使用基本方法,但是无法获得自动建议下拉菜单的X路径
I tired using the basic method but unable to get the X path of the auto suggestion drop down
无法单击下拉列表
package basic;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class goibibo {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new ChromeDriver();
driver.get("https://www.goibibo.com/");
new WebDriverWait(driver, 20)
.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gosuggest_inputSrc']")))
.sendKeys("Mum");
List<WebElement> myList = new WebDriverWait(driver, 20).until(
ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@id=\"react-autosuggest-1\"]")));
for (WebElement element : myList) {
if (element.getText().contains("Mumbai"))
;
element.click();
}
}
}
推荐答案
Chrome浏览器
首先,如何在Chrome浏览器中查找自动填充框的XPATH打开网站,而不是单击检查"元素并立即单击源"选项卡,单击以打开自动填充框,然后按 F8 暂停调试器的键.然后单击元素"选项卡,您可以轻松获取xpath参考下面的快照,以获取更多信息.因此它将冻结您的HTML.
Chrome Browser
First how to Find XPATH of auto populate box in Chrome Browser open your website than click on Inspect element and click on source Tab now, click for opening your auto populate box and Press F8 Key for pause debugger. Then click on your Element tab and you can easily get your xpath refer below snap for more information. so it will freeze your HTML.
现在单击Elements并创建自己的xpath.
Now click on Elements an Create your own xpath.
第二个如何在Firefox中查找自动填充"框的xpath-打开Firefox,然后右键单击并单击网站上的检查元素.有动画选项,因此它将打开所有DOM扩展,如下图所示.因此,通过阅读此dom结构,您可以轻松创建XPATH.
Second how to find xpath of Auto Populate box in Firefox - Open your Firefox and Right click and click on inspect elements on your website. there is option of animation so it will open all your DOM Expanded like below image. so by reading this dom structure you can create easily your XPATH.
不是如何从自动填充框中查找元素.为此,请参见下面的代码段.
Not how to find Elements from auto populate box. Refer below code snippet for that.
package com.software.testing;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Testingclass extends DriverFactory {
private static WebDriver driver = null;
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "your driver path");
driver = new ChromeDriver();
driver.get("https://www.goibibo.com/");
new WebDriverWait(driver, 20)
.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gosuggest_inputSrc']")))
.sendKeys("A");
Thread.sleep(1000);
List<WebElement> myList = new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfAllElementsLocatedBy(
By.xpath("//div[@class='dib marginL10 pad0 textOverflow width90']/div/span")));
for (int i = 0; i < myList.size(); i++) {
System.out.println(myList.get(i).getText());
if (myList.get(i).getText().equals("Ahmedabad")) {
myList.get(i).click();
break;
}
}
}
}
这篇关于如何处理“来自"中的自动建议和“目的地"该网站的框"https://www.goibibo.com/"硒中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!