WebDriver????θ???????y???
???????????? ???????[ 2015/3/27 14:58:57 ] ????????WebDriver ?????????? ???????
????????????????У????????????????????????y?????selenium1.0?????????????y?????????
??????????2.0?в???иe???????????????????????click???????????y??????????link???????button??????click??????????????????????????????????
?????????????????????????????????????????y??????????????????????????????????????????esc??????????????????????????????????ó?????
????????????????????????????????ù???????????£?
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
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.firefox.FirefoxProfile;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class TestActive {
WebDriver driver = null;
Actions action = null;
Robot robot = null;
@BeforeMethod
public void setUp(){
try {
robot = new Robot();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.setProperty(“webdriver.firefox.bin”?? “D:/Firefox/firefox.exe”);
FirefoxProfile file = new FirefoxProfile();
DesiredCapabilities ds = DesiredCapabilities.firefox();
ds.setCapability(FirefoxDriver.PROFILE?? file);
driver = new FirefoxDriver(ds);
action = new Actions(driver);
}
@AfterMethod
public void tearDown(){
}
@Test
public void start(){
driver.get(“http://www.baidu.com”);
driver.manage().window().maximize();
//????????????y???????
WebElement button = driver.findElement(By.xpath(“//*[@id='nv']/a[5]“));
//????????????????
action.contextClick(button).perform();
//??ESC??????????y?????
robot.keyPress(KeyEvent.VK_ESCAPE);
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11