moveByOffset()。contextClick()在WebElement外部单击

时间:2015-12-16 05:47:27

标签: selenium-webdriver

我是Selenium WebDriver和Programming的新手。我试图右键单击链接(Selenium Standalone Server下的http://docs.seleniumhq.org/download/2.48.2链接),但下面的代码右键单击链接的外部,因此上下文菜单不相关。如何右键单击上面的链接?我选择了正确的xpath但仍然......

    WebElement dom = obj.findElement(By.xpath("/html/body/div/div[2]/div[2]/p[3]/a"));
    Thread.sleep(3000);
    Actions act = new Actions(obj);
    int x = dom.getLocation().getX();
    int y = dom.getLocation().getY();
    act.moveByOffset(x,y).contextClick().build().perform();
    Thread.sleep(5000);
    act.sendKeys(Keys.DOWN).build().perform();
    Thread.sleep(2000);
    act.sendKeys(Keys.DOWN).build().perform();
    Thread.sleep(2000);
    act.sendKeys(Keys.ENTER).build().perform();
    Thread.sleep(2000);
    obj.quit();

1 个答案:

答案 0 :(得分:0)

如果你想右键点击下载链接(xpath =。// * [@ id ='mainContent'] / p [3] / a)那么

 Actions rightClick=new Actions(driver);
rightClick.contextClick(driver.findElement(By.xpath(".//*[@id='mainContent']/p[3]/a"))).build().perform();

让我知道它是如何运作的。

谢谢, 穆拉利