我已经在MouseHover选项卡上创建并执行了 and 选项卡上的https://www.spicejet.com/功能,但它不适用于下面的代码。
有人能建议代码中缺少什么吗?
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();
}
}发布于 2020-05-20 21:58:23
要演示使用Selenium在https://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();}}

发布于 2020-05-20 11:32:04
您是否尝试过在没有"build“的情况下编写它?:-)如果它不能工作,您确定xpath是正确的吗?
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath("//*[@id=\"highlight-addons\"]")));
action.perform();发布于 2020-05-20 14:07:02
一切都是正确的。只需在get方法之后添加10秒的睡眠,如下所示
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();https://stackoverflow.com/questions/61910580
复制相似问题