Selenium 通过动态xPath定位webelement时发生InvalidArgumentexception
我希望鼠标悬停在Flipkart中的“Books&More”并查看下拉列表。 使用的代码如下所示:Selenium 通过动态xPath定位webelement时发生InvalidArgumentexception,selenium,xpath,dynamic,Selenium,Xpath,Dynamic,我希望鼠标悬停在Flipkart中的“Books&More”并查看下拉列表。 使用的代码如下所示: WebElement Booksxpath=driver.findElement(By.xpath("//span[text()='Books & More']")); actions.moveToElement(Booksxpath).build().perform(); 代码给出了错误: org.openqa.selenium.InvalidArgumentexception:缺少“
WebElement Booksxpath=driver.findElement(By.xpath("//span[text()='Books & More']"));
actions.moveToElement(Booksxpath).build().perform();
代码给出了错误:
org.openqa.selenium.InvalidArgumentexception:缺少“type”参数
以下是你问题的答案: 确保您获得
操作的帮助
类并使用导入org.openqa.selenium.interactions.Actions代码>
仅限
以下代码块将浏览到https://www.flipkart.com/
并将鼠标悬停在书籍和更多书籍上,您可以查看下拉列表:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class Q45262660_Flipcart_MouseHover
{
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.flipkart.com/");
WebElement Booksxpath = driver.findElement(By.xpath("//span[text()='Books & More']"));
Actions act = new Actions (driver);
act.moveToElement(Booksxpath).perform();
}
}
如果这能回答您的问题,请告诉我。您可能想看看这个-实际上我下载了最新的Gecko驱动程序,它解决了问题。