20210707web 作业

本贴最后更新于 1227 天前,其中的信息可能已经水流花落
24 回帖
请输入回帖内容 ...
  • 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);
        }
    
  • 其他回帖
  • 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 回复
  • 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 更新了该回帖
  • 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 回复
  • 查看更多回帖