20210707web 作业

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

    满分

  • 其他回帖
  • 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 回复
  • Noone

    package cn.com.test;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Set;

    import org.openqa.selenium.chrome.ChromeDriver;

    public class findElement {

    public static void main(String[] args) {

    ChromeDriver driver = new ChromeDriver();
    
    driver.get("http://www.baidu.com");
    
    driver.findElementByXPath("//input[@id='kw' and @name='wd']").sendKeys("测试派");
    
    driver.findElementByCssSelector("#su").click();
    
    try {
    	Thread.sleep(1000);
    } catch (InterruptedException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }
    
    driver.findElementByXPath("//em[text()=\"测试派\"]/parent::a").click();
    
    try {
    	Thread.sleep(1000);
    } catch (InterruptedException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }
    
    Set<String> winHandels=driver.getWindowHandles();// 得到当前窗口的set集合
    List<String> it = new ArrayList<String>(winHandels); // 将set集合存入list对象
    driver.switchTo().window(it.get(1));// 切换到弹出的新窗口
    
    
    driver.findElementById("navLogin").click();
    
    try {
    	Thread.sleep(1000);
    } catch (InterruptedException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }
    
    // 登录
    driver.findElementById("nameOrEmail").sendKeys("输入账号");
    
    driver.findElementById("loginPassword").sendKeys("输入密码");
    
    try {
    	Thread.sleep(1000);
    } catch (InterruptedException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }
    
    // 登录
    driver.findElementById("loginBtn").click();
    
    try {
    	Thread.sleep(1000);
    } catch (InterruptedException e1) {
    	// TODO Auto-generated catch block
    	e1.printStackTrace();
    }
    
    // 点击 ‘领域’标签    /html/body/header/nav/a[2]
    driver.findElementByXPath("/html/body/header/nav/a[2]").click();
    
    
    try {
    	Thread.sleep(5000);
    } catch (InterruptedException e) {
    	// TODO Auto-generated catch block
    	e.printStackTrace();
    }
    
    driver.quit();
    

    }
    }

    1 回复
  • scb21sunny

    QQ截图20210709150132.png
    QQ截图20210709150149.png
    QQ截图20210709150142.png
    QQ截图20210709150204.png
    QQ截图20210709150157.png

    1 回复
  • 查看更多回帖