在.NET中使用PhantomJS硒webdriver的时候Element.Click不执行 [英] Element.Click not executed when using PhantomJS selenium webdriver in .Net

查看:329
本文介绍了在.NET中使用PhantomJS硒webdriver的时候Element.Click不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的使用硒IWebdriver的Firefox和Chrome浏览器实现完美的作品我们现有的工具。

I am using our existing tool that works perfectly using the Firefox and Chrome implementations of the Selenium IWebdriver.

我现在所做的使用PhantomJS实施一些试验。 到目前为止,一切都很好。但是,当我想点击一个按钮,它什么都不做。

I am now doing some experimentation using the PhantomJS implementation. So far so good. However, as soon as I want to click a button it does nothing.

我可以检索元素,但是,仔细一看它的属性选定属性状态如下:

I can retrieve the element, however, looking closer at its properties the 'Selected' property states the following:

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

我会收集这是不执行我的点击,但是,我不能从这个错误信息作出正面或反面的原因。使用谷歌也没有帮助。

I would gather this is the cause that my click is not executed, however, I cannot make heads or tails from this error message. using Google did not help either.

任何帮助将是非常美联社preciated。

Any help would be much appreciated.

在此先感谢。

推荐答案

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

We had a lot of similar issues with PhantomJS.

因此​​,几个步骤来找出根本原因吧。

So, couple of steps to figure out what the root cause to it

  1. 设置你的屏幕尺寸(如意见建议; PhantomJS采用400x300的默认情况下):

  1. Set you screen size (as suggested in comments; PhantomJS uses 400x300 by default):

driver.Manage().Window.Size = new Size(1920, 1080); //Size is type in System.Drawing"

  • 使用来验证你的元​​素其实是可见的:

  • Use to verify that your element is actually visible:

    new WebDriverWait(driver,
    TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.Id(login))));
    

  • 点击支持JavaScript的元素

  • Click on the element with Javascript

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

  • 这篇关于在.NET中使用PhantomJS硒webdriver的时候Element.Click不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆