.net - 在 .Net 中使用 PhantomJS selenium webdriver 时不执行 Element.Click

标签 .net selenium selenium-webdriver phantomjs ghostdriver

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

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

我可以检索元素,但是,仔细查看其属性,“Selected”属性声明如下:

    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"}

我认为这是我的点击未执行的原因,但是,我无法从该错误消息中得出正面或反面。使用谷歌也没有帮助。

任何帮助将非常感激。

提前致谢。

最佳答案

我们在 PhantomJS 上有很多类似的问题。

因此,通过几个步骤来找出其根本原因

  • 设置屏幕尺寸(如评论中所建议;PhantomJS 默认使用 400x300):
    driver.Manage().Window.Size = new Size(1920, 1080); //Size is type in System.Drawing"
    
  • 用于验证您的元素是否实际可见:
    new WebDriverWait(driver,
    TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.Id(login))));
    
  • 单击带有 Javascript 的元素
    IJavaScriptExecutor js = _driver as IJavaScriptExecutor;
    js.ExecuteScript("arguments[0].click();", buttonToClick); //buttonToClick is IWebElement
    

  • 对于 Java 如下:
  • 屏幕尺寸
    driver.manage().window().setSize(new Dimension(width, height));
    
  • 验证元素是否可见
    WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("LOCATOR")));
    
  • 用JS点击
    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("arguments[0].click();", buttonToClick); //buttonToClick is WebElement
    
  • 关于.net - 在 .Net 中使用 PhantomJS selenium webdriver 时不执行 Element.Click,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19663963/

    相关文章:

    用于人类可读模式匹配的 C# 库?

    java - 当应用程序切换到新方法时 Firefox 崩溃

    selenium - 如何使用webdriver使用不同版本的Firefox?

    javascript - 尝试使用 cucumber.js 实现页面对象模型时出错

    javascript - 如何从 Selenium 中的日期选择器中选择今天的日期和时间(+15 分钟)

    c# - 没有 .svc 的 WCF 服务相对 uri

    c# - 一般将对象转换为 'real' 类型

    .net - Windows Azure 中的 ASP.net 应用程序部署

    c# - Selenium IE 自动化

    php - 使用 php 在 webdriver 中模拟按键