簡體   English   中英

Selenium WebDriver會話

[英]Selenium WebDriver Session

我是在這里學習:P的新手,這可能是一個非常基本的問題,但我只是不知道該如何提問或搜索。

因此,我決定使用selenium在Java中制作一個網頁爬蟲,並且我注意到如果終止會話的速度不及凍結=(所以這意味着我必須經常調用.quit()並繼續打開新的WebDriver還是有一種與網站持續互動的方法?

例如:我希望打開Goog​​le。 鍵入“ pie”並單擊搜索,也許我不喜歡該結果,並希望搜索“ apple pie”並保持更長的時間?

這就是我在游戲時間練習中所做的事情。 您可以利用它。

String[] location = new String[] { 
                                   "Los Angeles", 
                                   "Santa Barbara",
                                   "San Jose" 
                                 };

 // Some code 

@Test
public void testSelServerDiceTest() throws Exception {
    for (int i = 0; i < location.length; i++) { // manually added for loop
        selenium.open("/");
        selenium.type("id=FREE_TEXT", "selenium RC JUnit");
        selenium.type("id=WHERE", location[i].concat(" CA"));
        selenium.click("xpath=//*[@id=\"searchSubmit\"]");
        selenium.waitForPageToLoad("30000");
        verifyTrue(selenium.isTextPresent("Search results:"));
        verifyTrue(selenium.isTextPresent("Search job title only"));
        verifyEquals("JUnit", selenium.getText("css=div.undoLabel"));
        verifyTrue(selenium.isTextPresent("selenium"));
        verifyTrue(selenium.isTextPresent("Search results: 1 - 1 of 1"));
        assertTrue(selenium.isTextPresent("Search results:"));
    }
}
//Some more code

編輯

// webdriver code snippet

@Test
public void testRemoteWebDriverDiceTest() throws Exception {
    for (int i = 0; i < location.length; i++) {
        driver.get(baseUrl + "/");
        driver.findElement(By.id("FREE_TEXT")).clear();
        driver.findElement(By.id("FREE_TEXT"))
                .sendKeys("selenium RC JUnit");
        driver.findElement(By.id("WHERE")).clear();
        driver.findElement(By.id("WHERE")).sendKeys(
                location[i].concat(" CA"));
        driver.findElement(By.xpath("//*[@id=\"searchSubmit\"]")).click();

        try {
            assertEquals("JUnit",
                    driver.findElement(By.cssSelector("div.undoLabel"))
                            .getText());
        } catch (Error e) {
            verificationErrors.append(e.toString());
        }

    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM