我在自动右键单击然后从中选择任何选项时遇到问题。
代码在Firefox中正常运行,但在Chrome中运行良好。
在那里,它似乎只是显示右键,但正常点击该元素。
我正在使用chromedriver 2.21和Selenium 2.50。
package mentor.qa.selenium;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Stack {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
// WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com/");
WebDriverWait wait = new WebDriverWait(driver, 30);
Thread.sleep(3000);
WebElement b = driver.findElement(By.linkText("About"));
Actions action = new Actions(driver);
action.moveToElement(b);
Thread.sleep(4000);
// Keys move = Keys.ARROW_DOWN;
// action.contextClick(b).sendKeys(move).sendKeys(Keys.ENTER).build().perform();
action.contextClick(b).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_DOWN).build().perform();
Thread.sleep(4000);
action.click().build().perform();
// action.keyDown(Keys.CONTROL).click().build().perform();
// action.contextClick(b).sendKeys(Keys.CONTROL).keyDown(Keys.CONTROL).sendKeys(String.valueOf(d)).sendKeys(Keys.ENTER).build().perform();
// action.click();
// action.contextClick(b);
Thread.sleep(4000);
// action.sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
// driver.findElement(By.partialLinkText("new tab")).click();
// action.sendKeys(Keys.RETURN).perform();
Thread.sleep(4000);
//driver.quit();
}
}