在.NET中使用PhantomJS硒webdriver的时候Element.Click不执行时候、PhantomJS、NET、webdriver

2023-09-04 01:18:09 作者:这颗吢丶永远等着你

我使用的使用硒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

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

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"

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

ECharts相关知识

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