首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >硒中的MouseHover功能

硒中的MouseHover功能
EN

Stack Overflow用户
提问于 2020-05-20 10:16:46
回答 4查看 284关注 0票数 0

我已经在MouseHover选项卡上创建并执行了 and 选项卡上的https://www.spicejet.com/功能,但它不适用于下面的代码。

有人能建议代码中缺少什么吗?

代码语言:javascript
复制
package SeleniumExamples;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;

public class MouseHoverConcept {

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver","./driver/chromedriver81.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
        driver.get("https://www.spicejet.com/");
        // create object for mouse hover
        Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(By.xpath("//*[@id=\"highlight-addons\"]"))).build().perform();
        Thread.sleep(3000);
        driver.findElement(By.linkText("SpiceMax")).click();
        //driver.quit();
    }
}
EN

回答 4

Stack Overflow用户

发布于 2020-05-20 21:58:23

要演示使用Seleniumhttps://www.spicejet.com/中的ADD选项卡上使用鼠标Hover的功能,需要为visibilityOfElementLocated()诱导WebDriverWait,您可以使用以下Locator Strategy

  • 代码块:

进口java.util.Collections;进口org.openqa.selenium.By;进口org.openqa.selenium.WebDriver;进口org.openqa.selenium.WebElement;进口org.openqa.selenium.chrome.ChromeDriver;进口org.openqa.selenium.chrome.ChromeOptions;进口org.openqa.selenium.interactions.Actions;进口org.openqa.selenium.WebElement进口org.openqa.selenium.support.ui.WebDriverWait;公共类mouseHover_spicejet_addons {公共静态虚主(String[] args) { System.setProperty("webdriver.chrome.driver","C:\WebDrivers\chromedriver.exe");ChromeOptions选项=新ChromeOptions();options.addArguments(“-start-maximized”);WebDriver驱动程序=新的ChromeDriver(选项);driver.get(“https://www.spicejet.com/"”);WebElement加载项=新的WebDriverWait(驱动程序,新的驱动程序)新WebDriverWait(driver,WebDriverWait‘SpiceMax’“).click();}}

  • 浏览器快照

票数 1
EN

Stack Overflow用户

发布于 2020-05-20 11:32:04

您是否尝试过在没有"build“的情况下编写它?:-)如果它不能工作,您确定xpath是正确的吗?

代码语言:javascript
复制
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//*[@id=\"highlight-addons\"]")));
action.perform();
票数 0
EN

Stack Overflow用户

发布于 2020-05-20 14:07:02

一切都是正确的。只需在get方法之后添加10秒的睡眠,如下所示

代码语言:javascript
复制
     driver.get("https://www.spicejet.com/");
     driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
     Thread.sleep(10000);


     // create object for mouse hover
        Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(By.xpath("//a[@id='highlight-addons']"))).build().perform();
        Thread.sleep(3000);
        driver.findElement(By.linkText("SpiceMax")).click();
        //driver.quit();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61910580

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档