20210707web 作业

本贴最后更新于 1229 天前,其中的信息可能已经水流花落
24 回帖
请输入回帖内容 ...
  • scb21sunny

    QQ截图20210708140039.png
    QQ截图20210708140049.png

    1 回复
  • 其他回帖
  • Tony
    public static void textControl(WebDriver driver, String name,String txt){
            WebElement element = driver.findElement(By.name(name));
            element.clear();
            element.sendKeys(txt);
        }
        public static void loginFeizhu() throws InterruptedException {
            WebDriver driver = init();
            driver.get("https://www.fliggy.com/");
    
            Thread.sleep(1000);
            /*
            //点击搜索框
            driver.findElement(By.xpath("//input[@placeholder=\"目的地/酒店/景点/签证等\"]")).click();
            Thread.sleep(1000);
            //选择机票
            driver.findElement(By.xpath("//div[@class=\"recommend-values\"]/span[contains(text(),\"机票\")and @data-itemindex=0]")).click();
            */
            textControl(driver,"depCityName", "上海"));
            textControl(driver,"arrCityName","长沙");
            textControl(driver,"depDate","2021-07-10");
    
            driver.findElement(By.cssSelector(".close-btn.delegate-click-381")).click();
            Thread.sleep(3000);
            driver.findElement(By.xpath("//form[@id=\"J_FlightForm\"]//button[text()=\"搜索\"]")).click();
    
            tearDown(driver);
        }
    
  • ke2beck
    package com.demo;
    
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class fliggyDemo {
      
        public static void inputElement(ChromeDriver driver, String eleName, String text) {
            WebElement element = driver.findElementByName(eleName);
            element.clear();
            element.sendKeys(text);
        }
        public static void main(String[] args) throws InterruptedException {
    
            System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.exe");
            ChromeDriver driver = new ChromeDriver();
    
            driver.get("https://www.fliggy.com/");
            Thread.sleep(2000);
            inputElement(driver,"depCityName","北京");
    
            inputElement(driver,"depDate","2021-07-10");
            driver.findElementByXPath("//span[text()='close']").click();
    
            inputElement(driver,"arrCityName","长沙");
            driver.findElementByXPath("//form[@id='J_FlightForm']//button").click();
    
            Thread.sleep(5000);
            driver.quit();
        }
    }
    
    
    1 回复
  • H

    public static void textControl(WebDriver driver, String name,String txt){ WebElement element = driver.findElement(By.name(name)); element.clear(); element.sendKeys(txt); } public static void loginFeizhu() throws InterruptedException { WebDriver driver = init(); driver.get("https://www.fliggy.com/"); Thread.sleep(1000); driver.findElement(By.xpath("//input[@placeholder="目的地/酒店/景点/签证等"]")).click(); Thread.sleep(1000); driver.findElement(By.xpath("//div[@class="recommend-values"]/span[contains(text(),"机票")and @data-itemindex=0]")).click(); */ textControl(driver,"depCityName", "上海")); textControl(driver,"arrCityName","长沙"); textControl(driver,"depDate","2021-07-10"); driver.findElement(By.cssSelector(".close-btn.delegate-click-381")).click(); Thread.sleep(3000); driver.findElement(By.xpath("//form[@id="J_FlightForm"]//button[text()="搜索"]")).click(); tearDown(driver); }

    1 回复
  • 查看更多回帖