【问题标题】:Element.Click not executed when using PhantomJS selenium webdriver in .Net在.Net中使用PhantomJS selenium webdriver时不执行Element.Click
【发布时间】:2013-10-29 16:28:37
【问题描述】:

我正在使用我们现有的工具,该工具可以完美地使用 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"}

我认为这是我的点击未执行的原因,但是,我无法从该错误消息中得出正面或反面。使用 Google 也无济于事。

任何帮助将不胜感激。

提前致谢。

【问题讨论】:

  • 你找到解决办法了吗?
  • 在使用 phantomjs 时尝试将浏览器窗口的大小增加到 (1200, 800)。我有同样的问题,它得到了解决。
  • 请分享您的代码和页面的HTML,这样我们才能解决实际问题。
  • 如果您使用 ID 定位元素,请尝试以不同的方式定位它。我遇到了非常奇怪的情况,即使用 ID 进行定位无法与 GhostDriver 一起使用。
  • 感谢大家的回复,很抱歉我没有回复这个问题。尽管有可能加快测试过程,但我们决定不使用此驱动程序。

标签: .net selenium selenium-webdriver phantomjs ghostdriver


【解决方案1】:

我们在使用 PhantomJS 时遇到过很多类似的问题。

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

  1. 设置你的屏幕尺寸(在 cmets 中建议;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
    

【讨论】:

  • 我如何在 java 中做同样的事情?
  • @B.J.A.A.Edited the answer with Java solution
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-08
  • 2016-02-14
  • 2016-06-10
  • 1970-01-01
  • 2016-01-17
相关资源
最近更新 更多