centos - 幻影JS 2.1.1 : "errorMessage":"Element is not currently visible and may not be manipulated

标签 centos webdriver phantomjs

我在 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 环境中执行代码,则会找到此元素。

最佳答案

关于centos - 幻影JS 2.1.1 : "errorMessage":"Element is not currently visible and may not be manipulated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36976681/

相关文章:

linux - git:在任何客户端推送后自动在服务器上运行 bash 脚本

javascript - 通过 Selenium WebDriver 从 JavascriptExecutor 接口(interface)使用 executeScript 方法时,arguments[0] 和 arguments[1] 是什么意思?

node.js - 在 phantomjs-prebuilt@2.1.13 安装脚本 'node install.js' 失败

javascript - 如何使用casperJS获取新页面的URL

ruby - 如何在 CentOS 6.9 上安装 Ruby?

php - 符号链接(symbolic link)在 apache 2.2 上不起作用

linux - 如何更改 godaddy 中的 dns 以指向 windows azure linux vms?

python : no module named selenium

python - 关闭 Selenium 中的通用弹出窗口

javascript - CasperJS/Javascript 选择多个选项