8

我正在使用我们现有的工具,该工具可以完美地使用 Selenium IWebdriver 的 Firefox 和 Chrome 实现。

我现在正在使用 PhantomJS 实现做一些实验。到目前为止,一切都很好。但是,只要我想单击一个按钮,它什么也不做。

我可以检索元素,但是,仔细查看其属性,“已选择”属性说明以下内容:

    Error Message => 'Element is not selectable' caused by Request => {"headers":{"Accept":"application/json, image/png","Connection":"Close","Host":"localhost:37704"},"httpVersion":"1.1","method":"GET","url":"/selected","urlParsed":{"anchor":"","query":"","file":"selected","directory":"/","path":"/selected","relative":"/selected","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/selected","queryKey":{},"chunks":["selected"]},"urlOriginal":"/session/fcaf88a0-40b4-11e3-960d-bdce3224aacf/element/%3Awdc%3A1383063211142/selected"}

我会收集这是我的点击没有执行的原因,但是,我无法从这个错误消息中做出正面或反面。使用谷歌也没有帮助。

任何帮助将非常感激。

提前致谢。

4

1 回答 1

8

PhantomJS 有很多类似的问题。

所以,几个步骤来找出它的根本原因

  1. 设置屏幕尺寸(如评论中所建议的那样;PhantomJS 默认使用 400x300):

    driver.Manage().Window.Size = new Size(1920, 1080); //Size is type in System.Drawing"
    
  2. 用于验证您的元素是否实际可见:

    new WebDriverWait(driver,
    TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.Id(login))));
    
  3. 使用 Javascript 单击元素

    IJavaScriptExecutor js = _driver as IJavaScriptExecutor;
    js.ExecuteScript("arguments[0].click();", buttonToClick); //buttonToClick is IWebElement
    

对于Java,它将如下所示:

  1. 屏幕尺寸

    driver.manage().window().setSize(new Dimension(width, height));
    
  2. 验证元素是否可见

    WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOCATOR")));
    
  3. 用JS点击

    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("arguments[0].click();", buttonToClick); //buttonToClick is WebElement
    
于 2014-11-17T15:01:50.107 回答