简体   繁体   English

如何使用 Selenium Java 处理 https://www.spicejet.com/ 的 PASSENGERS 字段的静态下拉列表

[英]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) , 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:浏览器快照:

spicejet_passengers

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过 selenium-webdriver 在 url http://www.spicejet.com/ 上执行多个操作并单击带有文本的链接作为会员登录 - How to perform multiple actions and click on the link with text as Member Login on the url http://www.spicejet.com/ through selenium-webdriver 无法通过 Selenium 和 Java 在 https://spicejet.com 中选择出发日期 - Unable to select depart date in https://spicejet.com through Selenium and Java 如何在 https://www.goibibo.com/hotels 上点击 SELECT ROOM 按钮 - How to click on SELECT ROOM button on https://www.goibibo.com/hotels using Selenium and Java How to select the autocomplete result that contains a certain phrase within the website https://www.easyjet.com/en using Selenium and Java - How to select the autocomplete result that contains a certain phrase within the website https://www.easyjet.com/en using Selenium and Java How to extract the text 73 from the text 1-16 of 73 results from the search result summary within https://www.amazon.com using Selenium and Java - How to extract the text 73 from the text 1-16 of 73 results from the search result summary within https://www.amazon.com using Selenium and Java driver.findelements(By.xpath) 在 https://www.amazon.com/ 上使用 Selenium Java 显示不一致的搜索结果 - driver.findelements(By.xpath) shows inconsistent search results on https://www.amazon.com/ using Selenium Java 如何使用Selenium for Java自动执行“ https://stage.masterpassteststore.com/configuration”上的设置? - How to automate settings on 'https://stage.masterpassteststore.com/configuration' using Selenium for Java? 如何使用 Selenium 和 Java 在 https://www.phptravels.net/ 网站中提取 HTML5 约束验证的文本? - How can I extract the text of HTML5 Constraint validation in https://www.phptravels.net/ website using Selenium and Java? 如何使用 Selenium 和 Java 在 https://www.phptravels.net/home 的聊天机器人表单输入字段中输入文本 - How to enter text with in the chat bot form input fields of https://www.phptravels.net/home using Selenium and Java 如何在Selenium WebDriver中使用Java处理灯箱 - How to handle lightbox using java in selenium webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM