Example script:
import java.util.List;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.testng.annotations.Test;
public class TestPhantomJS {
@Test
public void GoogleSearch(){
WebDriver driver = new PhantomJSDriver();
// WebDriver driver = new FirefoxDriver();
driver.findElement(By.name("q")).sendKeys("phantomjs");
driver.findElement(By.name("q")).submit();
List<WebElement> sites = driver.findElements(By.xpath("//cite"));
System.out.println(driver.getTitle());
int index=1;
for(WebElement site: sites){
String siteName=site.getText();
if(!siteName.equalsIgnoreCase(""))
System.out.println(index+++":--"+site.getText());
}
driver.close();
}
}
//Copied this from web
//Copied this from web
No comments:
Post a Comment