20210707web 作业

本贴最后更新于 1229 天前,其中的信息可能已经水流花落
24 回帖
请输入回帖内容 ...
  • Tony
    public static void loginYouxuePai() throws InterruptedException {
            System.setProperty("webdriver.chrome.driver", "D:\\Program Files\\chromedriver.exe");
            ChromeDriver webDriver = new ChromeDriver();
    
            webDriver.get("https://www.baidu.com");
    
            WebElement kw = webDriver.findElement(By.id("kw"));
            kw.sendKeys("测试派");
    
            WebElement su = webDriver.findElement(By.id("su"));
    
            String windowHandle = webDriver.getWindowHandle();
            su.click();
    
            Thread.sleep(3000);
    
    
            WebElement element = webDriver.findElement(By.xpath("//em[text()=\"测试派\"]/parent::*"));
            element.click();
            Thread.sleep(3000);
    
            webDriver.switchTo().defaultContent();
            webDriver.manage().window().maximize();
            System.out.println("页面跳转成功");
    
            Set<String> windowHandles = webDriver.getWindowHandles();
            for (String s : windowHandles){
                Thread.sleep(1000);
                if (webDriver.switchTo().window(s).getTitle().equals("测试派 - 软件测试工程师的心灵社区")){
                    windowHandle = s;
                    break;
                }
            }
    
            webDriver.switchTo().window(windowHandle);
            Thread.sleep(1000);
            //element = webDriver.findElement(By.cssSelector(".fn__two-line"));
            element =  webDriver.findElement(By.xpath("//a[@href=\"http://testingpai.com/article/1625637760328/comment/1625650976958#comments\"]/div"));
            if (element != null){
                System.out.printf("找到元素了");
            }
    
            element.click();
        }
    
    1 操作
    Tony 在 2021-07-08 15:13:28 更新了该回帖
  • 其他回帖
  • mary369

    #coding:utf-8

    from selenium import webdriver
    from time import sleep

    browser = webdriver.Chrome()
    browser.maximize_window()
    browser.get('https://www.baidu.com')
    browser.implicitly_wait(5)

    browser.find_element_by_xpath('//input[@id="kw"]').send_keys(u'测试派')
    browser.find_element_by_xpath('//input[@id="su"]').click()
    browser.find_element_by_xpath('//*[@id="3"]/h3/a').click()

    handles = browser.window_handles
    browser.switch_to.window(handles[1])
    browser.find_element_by_xpath('//a[text()="领域"]').click()
    sleep(5)

    browser.quit()

  • 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 回复
  • 查看更多回帖