selenium web 驱动程序鼠标悬停在 IE 8 中无法正常工作
selenium web driver Mouse over not working as expected in IE 8
在 http://www.spicejet.com/ 中,我试图从 "About Us">"Spice Route Magazine" 中单击 link "February 2016",下面是我使用的脚本。有两个问题:
1) 该脚本在 firefox 中运行良好,但在 IE 中运行不正常。为什么? (在 IE 中,菜单一直闪烁,即使在我设置的隐式等待 30 秒后,它也不会计时)
2) 即使在 firefox 中,该脚本也仅适用于 Thread.sleep 而不适用于条件等待。为什么?
代码:
将鼠标悬停在 "About Us"
Actions mAction = new Actions(wDriver);
mAction.moveToElement(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/a"))).build().perform();
将鼠标悬停在 "Spice Route Magazine"
mAction.moveToElement(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/ul/li[5]/a"))).build().perform();
将鼠标悬停并单击 "February 2016"
mAction.moveToElement(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/ul/li[5]/ul/li[1]/a"))).click().build().perform();
每次鼠标悬停在 Thread.sleep(5000)
之间时,上述代码在 Firefox 中运行良好。但是像 owait.until(ExpectedConditions.visibilityOf(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/ul/li[5]/a"))));
这样的条件等待等待 "Spice Route Magazine" 的可见性和 owait.until(ExpectedConditions.visibilityOf(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/ul/li[5]/ul/li[1]/a"))));
等待 "February 2016" 的可见性,它不起作用。
我也尝试过使用 link 文本的不同定位器,但没有用。请帮忙。
在谷歌搜索了一段时间后,在初始化之前对 IE 驱动程序进行了以下设置,我让它工作了:
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING,false);
capab.setCapability(InternetExplorerDriver.NATIVE_EVENTS,false);
wDriver = new InternetExplorerDriver(capab);
我仍然没有第二个问题的答案..
在 http://www.spicejet.com/ 中,我试图从 "About Us">"Spice Route Magazine" 中单击 link "February 2016",下面是我使用的脚本。有两个问题: 1) 该脚本在 firefox 中运行良好,但在 IE 中运行不正常。为什么? (在 IE 中,菜单一直闪烁,即使在我设置的隐式等待 30 秒后,它也不会计时) 2) 即使在 firefox 中,该脚本也仅适用于 Thread.sleep 而不适用于条件等待。为什么?
代码: 将鼠标悬停在 "About Us"
Actions mAction = new Actions(wDriver);
mAction.moveToElement(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/a"))).build().perform();
将鼠标悬停在 "Spice Route Magazine"
mAction.moveToElement(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/ul/li[5]/a"))).build().perform();
将鼠标悬停并单击 "February 2016"
mAction.moveToElement(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/ul/li[5]/ul/li[1]/a"))).click().build().perform();
每次鼠标悬停在 Thread.sleep(5000)
之间时,上述代码在 Firefox 中运行良好。但是像 owait.until(ExpectedConditions.visibilityOf(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/ul/li[5]/a"))));
这样的条件等待等待 "Spice Route Magazine" 的可见性和 owait.until(ExpectedConditions.visibilityOf(wDriver.findElement(By.xpath("//*[@id='smoothmenu1']/ul/li[2]/ul/li[5]/ul/li[1]/a"))));
等待 "February 2016" 的可见性,它不起作用。
我也尝试过使用 link 文本的不同定位器,但没有用。请帮忙。
在谷歌搜索了一段时间后,在初始化之前对 IE 驱动程序进行了以下设置,我让它工作了:
DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
capab.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING,false);
capab.setCapability(InternetExplorerDriver.NATIVE_EVENTS,false);
wDriver = new InternetExplorerDriver(capab);
我仍然没有第二个问题的答案..