[英]How to handle the static dropdowns of PASSENGERS field of https://www.spicejet.com/ using Selenium Java
Am practicing on Spice jet site to automate.Here am giving code what i have wrote.我正在 Spice jet 网站上练习以实现自动化。这里给出了我写的代码。
package NewPackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class HandlingStaticDropdowns
{
public static void main(String[] args)throws Exception
{
System.setProperty("webdriver.chrome.driver","C:\\SeleniumJars\\chromedriver.exe");
WebDriverdriver=new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.get("https://www.spicejet.com/");
Select s = newSelect(driver.findElement(By.id("ctl00_mainContent_ddl_Adult")));
s.selectByValue("3");
s.selectByIndex(6);
s.deselectByVisibleText("5");
}
}
Am not getting proper output.我没有得到正确的输出。 Please help me out and let me know what I did wrong.请帮助我,让我知道我做错了什么。
The PASSENGERS field contains of 3(three) dropdowns , one for the number of Adult , one for the number of Child and the other for the number of Infant . PASSENGERS字段包含 3(三个) 下拉列表,一个是Adult的数量,一个是Child的数量,另一个是Infant的数量。 To select 5 for Adult , 3 for Child and 1 for Infant you need to to induce WebDriverWait for the visibilityOfElementLocated()
and you can use the following Locator Strategies :要为Adult选择5 个,为Child选择3 个,为Infant选择1 个,您需要为visibilityOfElementLocated()
引入WebDriverWait ,您可以使用以下定位器策略:
Code Block:代码块:
public class A_demo { public static void main(String[] args) throws Exception { System.setProperty("webdriver.chrome.driver", "C:\\\\Utility\\\\BrowserDrivers\\\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); options.setExperimentalOption("useAutomationExtension", false); options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation")); WebDriver driver = new ChromeDriver(options); driver.get("https://www.spicejet.com/"); new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div#divpaxinfo"))).click(); Select selectAdult = new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divpaxOptions div.passengers-wrap2 p>select[name$='_Adult']")))); selectAdult.selectByVisibleText("5"); Select selectChild = new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divpaxOptions div.passengers-wrap2 p>select[name$='_Child']")))); selectChild.selectByVisibleText("3"); Select selectInfant = new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divpaxOptions div.passengers-wrap2 p>select[name$='_Infant']")))); selectInfant.selectByVisibleText("1"); } }
Browser Snapshot:浏览器快照:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.