Refine search
import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.openqa.selenium.WebDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver; public class Test{ private WebDriver driver; private String output; public Document getDocument(String input) { driver = new HTMLUnitDriver(true); //the param true turns on javascript. driver.get(input); output = driver.getPageSource(); driver.quit(); return Jsoup.parse(output); } }
public static void main(String[] args) { File file = new File("C:/Program Files/phantomjs-2.0.0-windows/bin/phantomjs.exe"); System.setProperty("phantomjs.binary.path", file.getAbsolutePath()); WebDriver driver = new PhantomJSDriver(); driver.get("http://www.google.com"); WebElement element = driver.findElement(By.name("q")); element.sendKeys("Guru99"); element.submit(); System.out.println("Page title is: " + driver.getTitle()); driver.quit(); }
reate a new instance of the html unit driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new HtmlUnitDriver(); // And now use this to visit Google driver.get("http://www.google.com"); System.out.println( driver.getPageSource()); driver.quit(); }
@Test public void chromeTest() { WebDriver driver = new ChromeDriver(); try { PageFactory .initElements(new AppiumFieldDecorator(driver, ofSeconds(15)), this); driver.get(new File("src/test/java/io/appium/java_client/hello appium - saved page.htm") .toURI().toString()); assertNotEquals(0, foundLinks.size()); assertNotEquals(0, main.size()); assertNull(trap1); assertNull(trap2); } finally { driver.quit(); } } }
public void testGoogle() throws Exception { WebDriver driver = new AndroidDriver(); driver.get("http://www.google.co.in"); Thread.sleep(4000); WebElement element = driver.findElement(By.name("q")); element.sendKeys("Welcome"); element.submit(); System.out.println("Page title is: " + driver.getTitle()); driver.quit(); }
public static void main(String[] args) { //System.setProperty("webdriver.chrome.driver", "./chromedriver.exe"); //WebDriver driver = new ChromeDriver(); WebDriver driver = new FirefoxDriver(); driver.get("file:///C:/Users/jgong/Desktop/a.html"); String html = driver.getPageSource(); System.out.println(html); driver.quit(); Document doc = Jsoup.parse(html); System.out.println(doc.html()); }
WebDriver driver = new FirefoxDriver(); driver.get("file://<Path>/div.html"); long starttime = System.currentTimeMillis(); //driver.findElement(By.cssSelector(".class")); //driver.findElement(By.className("class")); //driver.findElement(By.cssSelector("#id")); //driver.findElement(By.id("id")); //driver.findElement(By.cssSelector("div")); //driver.findElement(By.tagName("div")); long stoptime = System.currentTimeMillis(); System.out.println(stoptime-starttime + " milliseconds"); driver.quit();
@Test public void shouldSearchWithEbay() { // And now use this to visit ebay driver.get("http://m.ebay.de"); // Find the text input element by its id WebElement element = driver.findElement(By.id("kw")); // Enter something to search for element.sendKeys("Nexus 5"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); driver.quit(); }
WebDriver driver = new FirefoxDriver(); driver.get("file://<Path>/div.html"); long starttime = System.currentTimeMillis(); //driver.findElement(By.className("class")); //driver.findElement(By.cssSelector("html body div")); //driver.findElement(By.id("id")); //driver.findElement(By.name("name")); //driver.findElement(By.tagName("div")); //driver.findElement(By.xpath("/html/body/div")); long stoptime = System.currentTimeMillis(); System.out.println(stoptime-starttime + " milliseconds"); driver.quit();
public class Wiki { @Test public void createAccount() throws InterruptedException { WebDriver driver = new FirefoxDriver(); WebDriverWait wait=new WebDriverWait(driver,60); driver.get("http://en.wikipedia.org/wiki/Main_Page"); driver.findElement(By.linkText("Create account")).click(); wait.until(ExpectedConditions.titleContains("Create account - Wikipedia, the free encyclopedia")); Assert.assertEquals("Create account - Wikipedia, the free encyclopedia",driver.getTitle()); driver.quit(); } }
WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get("http://www.adspapa.com/"); WebElement catBox = driver.findElement(By.xpath("html/body/table[1]/tbody/tr/td/table/tbody/tr/td[1]/table")); List<WebElement> catValues = catBox.findElements(By.tagName("a")); for(int i=0;i<catValues.size();i++) { catValues.get(i).click(); System.out.println(driver.getTitle()); driver.navigate().back(); catBox = driver.findElement(By.xpath("html/body/table[1]/tbody/tr/td/table/tbody/tr/td[1]/table")); catValues = catBox.findElements(By.tagName("a")); } driver.quit();