Reputation: 19
I'm a newbie here learning :P Probably a very basic question but I just don't know how to ask or search for it.
So I decided to make a crawler for a webpage in java using selenium, and I noticed if I do not terminate the session fast enough than it freezes =( So does that mean I have to call .quit() often and keep opening new WebDriver? Or is there a way to continually interact with the website?
Like for example: I wish to open up Google. Type "pie" and click search, maybe I didn't like the result and wish to search for "apple pie" and keep doing that for extended period of time?
Upvotes: 0
Views: 1193
Reputation: 4715
This is I what I had done for my playtime practice. YOu can make use of it.
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
EDIT
// 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());
}
}
}
Upvotes: 1