Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Selenium WebDriver MoveToElement-隐藏元素、悬停和切换类_C#_Jquery_Selenium_Selenium Webdriver - Fatal编程技术网

C# Selenium WebDriver MoveToElement-隐藏元素、悬停和切换类

C# Selenium WebDriver MoveToElement-隐藏元素、悬停和切换类,c#,jquery,selenium,selenium-webdriver,C#,Jquery,Selenium,Selenium Webdriver,SeleniumWebDriver:2.35。 FireFox:25.0 我想将鼠标移到一个div上,这将使隐藏的图像变得可见,然后单击该图像。我读过帖子,还有其他的。一般的答案是采取以下形式: action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath("/expression-here")).click().build().perform(); 但是,这在下面的示例中不起作用: html: CSS: C#测试代

SeleniumWebDriver:2.35。 FireFox:25.0

我想将鼠标移到一个div上,这将使隐藏的图像变得可见,然后单击该图像。我读过帖子,还有其他的。一般的答案是采取以下形式:

action.moveToElement(we).moveToElement(webdriver.findElement(By.xpath("/expression-here")).click().build().perform();
但是,这在下面的示例中不起作用:

html:

CSS:

C#测试代码:

IWebElement testDiv = WebDriver.FindElement( By.Id( "bb_testDiv" ) );            
Actions builder = new Actions( WebDriver );
Actions hoverClick = builder.MoveToElement( testDiv ).MoveToElement( testDiv.FindElement( By.ClassName( "bb_matchImgTest" ) ) ).Click();
hoverClick.Build().Perform();
问题是没有触发click事件。此外,该元素保持可见,因此任何后续鼠标悬停都会将其隐藏。当然,这一切都适用于手动测试


问题似乎出在悬停事件上。如果我将其分为两个事件-mouseenter和mouseleave(而不是hover)以及addClass和removeClass(而不是toggleClass),那么它就可以工作了。只是想知道是否有可能将hover?

作为元素使用。bb_standardHidden被隐藏这可能是原因,因为MoveToElement未按您的需要工作

IWebElement testDiv = WebDriver.FindElement( By.Id( "bb_testDiv" ) );            
Actions builder = new Actions( WebDriver );
Actions hoverClick = builder.MoveToElement( testDiv ).MoveByOffset( x, y ).Click();
hoverClick.Build().Perform();

使用x和y以确保鼠标将位于隐藏的图片上。

作为元素。bb_standardHidden被隐藏这可能是原因,因为MoveToElement未按需要工作

IWebElement testDiv = WebDriver.FindElement( By.Id( "bb_testDiv" ) );            
Actions builder = new Actions( WebDriver );
Actions hoverClick = builder.MoveToElement( testDiv ).MoveByOffset( x, y ).Click();
hoverClick.Build().Perform();

使用x和y以确保鼠标将位于隐藏的图片上方。

谢谢您的想法,但这没有帮助。移动到testDiv时会显示隐藏图像,但不会单击它。这似乎与hover事件有关,因为如果我将hover更改为mouseenter/mouseleave,那么一切都可以正常工作。感谢您的想法,但它没有帮助。移动到testDiv时会显示隐藏图像,但不会单击它。这似乎与hover事件有关,因为如果我将hover更改为mouseenter/mouseleave,那么一切都可以正常工作。
IWebElement testDiv = WebDriver.FindElement( By.Id( "bb_testDiv" ) );            
Actions builder = new Actions( WebDriver );
Actions hoverClick = builder.MoveToElement( testDiv ).MoveToElement( testDiv.FindElement( By.ClassName( "bb_matchImgTest" ) ) ).Click();
hoverClick.Build().Perform();
IWebElement testDiv = WebDriver.FindElement( By.Id( "bb_testDiv" ) );            
Actions builder = new Actions( WebDriver );
Actions hoverClick = builder.MoveToElement( testDiv ).MoveByOffset( x, y ).Click();
hoverClick.Build().Perform();