WebDriver实现自动化打开IE中的google网页并实现搜索
webdriver实现自动化打开ie中的google网页并实现搜索,需要导入webdriver相关的jar包,设置好环境变量。
package com.feng.domain;
import org.openqa.selenium.by;
import org.openqa.selenium.webdriver;
import org.openqa.selenium.webelement;
import org.openqa.selenium.ie.internetexplorerdriver;
import org.openqa.selenium.remote.desiredcapabilities;
public class testwebdriver {
public static void main(string[] args) {
// todo auto-generated method stub
system.setproperty("webdriver.ie.driver", "c:\\testwebdriver\\iedriverserver.exe");
desiredcapabilities iecapabilities = desiredcapabilities.internetexplorer();
iecapabilities.setcapability(internetexplorerdriver.introduce_flakiness_by_ignoring_security_domains, true);
webdriver driver = new internetexplorerdriver(iecapabilities);
driver.get("http://www.google.com.hk/");
try {
thread.sleep(6000);
} catch (interruptedexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
// system.out.println("the current url is:" + driver.getcurrenturl());
webelement element = driver.findelement(by.name("q"));
element.sendkeys("days");
webelement elementbtn = driver.findelement(by.xpath("//input[@name='btng']"));
elementbtn.click();
try {
thread.sleep(6000);
} catch (interruptedexception e) {
// todo auto-generated catch block
e.printstacktrace();
}
driver.close();
}
}