问题
I am using selenium webdriver for automation tool creation in C#. That automation working fine windows 7, but not working windows 10.
ex.
driver.FindElement(By.XPath("//button[@type='submit']")).Click();
Click not working.
error msg.
threw an exception of type 'OpenQA.Selenium.WebDriverException'
base: {"The HTTP request to the remote WebDriver server for URL http://localhost:7057/hub/session/c335c107-a5ba-48a1-8858-58de998c62dc/element/%7B0678bf84-d09c-43d4-a4cf-ea35f73168a8%7D/click timed out after 60 seconds."}.
回答1:
Try this:
Instead of .Click();*
use .SendKeys(Keys.Return);
driver.FindElement(By.XPath("//button[@type='submit']")).SendKeys(Keys.Return);
回答2:
i got same error when FireFox updated to 47.0.1 version, because WebDriver was not compatible with that version without additional libraries or WebDriver update. Try to update Selenium, new 3.0.0 beta update came out 2016-08-04 at http://www.seleniumhq.org/download/
回答3:
Update your browsers and drivers, make sure the browsers and driver version match - you can't use driver version 80 on browser version 70, that is why you get TimeoutException
That being said,
There are many reasons why click might not work, some of them:
- Element is not intractable.
- Other element will receive the click.
- For some driver implementations, a bug on some end cases.
- Rare - no apparent reason.
First, try the obvious one (submit, not click)
driver.FindElement(By.XPath("//button[@type='submit']")).Submit();
If the above didn't work, continue here.
In order to bypass all the Click()
logic, use JavaScript to perform a raw click.
var element = driver.FindElement(By.XPath("//button[@type='submit']"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", element);
As an extension method
public static void JavaScriptClick(this IWebElement element)
{
// get the driver
var driver = (IJavaScriptExecutor)((IWrapsDriver)element).WrappedDriver;
// execute the click
driver.ExecuteScript("arguments[0].click();", element);
}
// usage
driver.FindElement(By.XPath("//button[@type='submit']")).JavaScriptClick();
Resources
You can check Selenium Extensions (open source) for more samples
under folder: /src/csharp/Gravity.Core/Gravity.Core/Extensions
https://github.com/gravity-api/gravity-core
https://www.nuget.org/packages/Gravity.Core
If you use C# you can install the package and use it's extensions directly.
https://www.nuget.org/packages/Gravity.Core/
Install-Package Gravity.Core
来源:https://stackoverflow.com/questions/38719797/selenium-web-driver-element-click-not-working-in-windows-10