我在 Cent OS 中使用带有 WebDriver 的 phantomjs 进行 headless 测试。适用于 Windows 的 phantomjs.exe 运行良好。但是当我为 Cent OS 制作 jar 文件时,会出现如下错误:
"errorMessage":"Element is not currently visible and may not be manipulated
或者
Error communicating with the remote browser. It may have died.
我有以下代码为 Cent OS 制作可执行 jar:
@Before
public void setUp()
{
logger.info("Inside setup().");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "phantomjs");
driver = new PhantomJSDriver(caps);
driver.manage().window().maximize();
logger.info("Exiting setUP().");
}
我只是放了一个try-catch block 来理解抛出的错误,发现下面的代码是错误的原因:
public void goToMyPageAfterLogin()
{
try
{
logger.info("Inside goToMyPageAfterLogin().");
driver.manage().window().maximize();
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//li[@id='header-mypage-top']//a")));
WebElement element = driver.findElement(By.xpath("//li[@id='header-mypage-top']//a"));
element.click();
logger.info("Exiting goToMyPageAfterLogin().");
}catch(Exception ex)
{
ex.printStackTrace();
}
}
无论如何都找不到这个 li 元素。但是,如果我使用 2.1.1 版的 phantomjs.exe 在 Windows 环境中执行代码,则会找到此元素。
最佳答案
你试过使用 JavaScriptExecutor 吗? http://selenium-solutions.blogspot.in/2012/11/enabling-hidden-element-using.html
关于centos - 幻影JS 2.1.1 : "errorMessage":"Element is not currently visible and may not be manipulated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36976681/