How to avoid MouseOver on Selenium Click()

前端 未结 2 1379
囚心锁ツ
囚心锁ツ 2020-12-22 14:01

In one of my Selenium test cases, I have the problem that there are MouseOver effects that I don\'t want to have. This is what I do:

  1. Click on the \"login\" but
相关标签:
2条回答
  • 2020-12-22 14:14

    As Andrew is right. If it is not happening manually then it should not happened here as well.

    You can also try to click using JavascriptExecutor

    WebElement element= driver.findElement(By.xpath("Your Xpath"));
    
    JavascriptExecutor executor = (JavascriptExecutor) driver;
    executor.executeScript("arguments[0].click();", element);
    

    Below is some example that how you can do it using C#

    Execute JavaScript using Selenium WebDriver in C#

    Hope it will help you :)

    0 讨论(0)
  • 2020-12-22 14:22

    I still don't know the real solution, but here's the dirty workaround I'm using:

    public static void Click(this IWebElement element, TestTarget target)
    {
        if (target.IsInternetExplorer)
        {
            var actions = new Actions(target.Driver);
            actions.MoveToElement(element).Perform();
            Thread.Sleep(500); // wait for the mouseover popup to appear
            element.SendKeys(Keys.Escape); // to close the popup (if any)
            actions.MoveToElement(element).DoubleClick().Perform(); // simple click is sometimes not enough in IE
        }
        else
        {
            element.Click();
        }
    }
    
    0 讨论(0)
提交回复
热议问题