20210707web 作业

本贴最后更新于 1267 天前,其中的信息可能已经水流花落
24 回帖
请输入回帖内容 ...
  • 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 回复
  • 其他回帖
  • scb21sunny

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

    1 回复
  • qingchen

    #导包
    from selenium import webdriver
    from time import sleep
    #创建一个驱动对象
    browser = webdriver.Chrome()
    #使用谷歌浏览器驱动打开浏览器
    browser.get('https://www.baidu.com')
    #设置抓取标签等待时间5秒
    browser.implicitly_wait(5)
    #通过id定位搜索框 填写测试派
    browser.find_element_by_id('kw"]').send_keys('测试派')
    #browser.find_element_by_xpath//input[@id='kw' and @name='wd']
    #通过xpah定位确定键 点击
    browser.find_element_by_xpath('//input[@id="su"]').click()
    #等待5秒
    time.sleep(5)

    #下面没网络了 视频看不成了 写不下去了

    #通过xpah定位测试派位置点击
    browser.find_element_by_xpath('//em[text()="测试派"]').click()

    browser.quit()

    1 回复
  • ke2beck
    package com.demo;
    import org.openqa.selenium.chrome.ChromeDriver;
    import java.util.Set;
    
    public class demo {
        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.baidu.com/");
            driver.findElementById("kw").sendKeys("测试派");
            driver.findElementById("su").click();
            Thread.sleep(1000);
            driver.findElementByPartialLinkText("软件测试工程师的心灵社区").click();
            Thread.sleep(1000);
            String search_handle = driver.getWindowHandle();
            Set<String> handles = driver.getWindowHandles();
            for (String handle : handles) {
                if (!handle.equals(search_handle)) {
                    driver.switchTo().window(handle);
                    Thread.sleep(1000);
                    driver.findElementById("navLogin").click();
                    Thread.sleep(1000);
                    driver.findElementById("nameOrEmail").sendKeys("ke2beck");
                    driver.findElementById("loginPassword").sendKeys("********");
                    driver.findElementById("loginBtn").click();
                    Thread.sleep(1000);
                    driver.findElementByXPath("/html/body/header/nav/a[2]").click();
                    Thread.sleep(5000);
                    driver.close();
                }
            }
            driver.quit();
        }
    }
    
    ```
    
    ```
    
    1 回复
  • 查看更多回帖