问题
I just updated my Chrome Driver to the latest version - 73.0.3683.68 and ever since my "Click" Function is not working properly (it does work at times, but not everytime).
Chrome version: Version 73.0.3683.75 (Official Build) (64-bit)
I code with C#.
The biggest problem is that Selenium acts as if the "Click" worked properly and moves on to the next function and there it fails because the element is not present on the screen yet.
It should be noted that prior to clicking on the element, we do verify that the element is clickable.
Is there a way to make sure the "Click" function actually occurred?
A function like Click and Verify?
Thanks.
回答1:
Hey I was able to resolve my issue by updating to ChromeDriver 74.0.3729.6. You will need to use the beta version of Chrome as well. In your code you will need to setup a binary path to point to Chrome Beta since it doesn't use the same path as the current release. Chrome reported in their documentation that it was sometimes sending clicks to the wrong element with version 73.0.3683.68.
Here is the site for more information: http://chromedriver.chromium.org/downloads Look at the release notes and you will find the information there.
I hope this resolves your issue.
回答2:
I am not sure what the click does but let's say it takes you to a new page. You could add a method that looks to see if the button you just clicked is still visible, if so, click it again. That being said, when you debug it and step into it, does it work? Maybe try a MoveToElement first? You could also add a java click instead which tends to be more reliable in all honesty.We added a try catch and did the c# click and then did a js click if the c# click failed. Best of both worlds.
public static void Click(IWebElement element)
{
var actions = new Actions(driver);
actions.MoveToElement((element));
actions.Click(element).Perform();
}
public static void JClick(IWebElement element)
{
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", element);
}
public static void LastChanceClick(IWebElement element)
{
try
{
Click(element);
}
catch (Exception)
{
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", element);
}
}
来源:https://stackoverflow.com/questions/55218443/selenium-click-not-working-chrome-driver-version-73-0-3683-68