Selenium 鼠标悬停在问题(u错误消息)上(u Can#x27 ;;t从void转换为WebElement

Selenium 鼠标悬停在问题(u错误消息)上(u Can#x27 ;;t从void转换为WebElement,selenium,selenium-webdriver,Selenium,Selenium Webdriver,鼠标悬停问题\u错误消息\u无法从void转换为WebElement 在WebElement创建行显示“无法从void转换为WebElement”。 附上截图 我的代码: import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import[enter image description here][1] org.openqa.selenium.WebElement;

鼠标悬停问题\u错误消息\u无法从void转换为WebElement

在WebElement创建行显示“无法从void转换为WebElement”。 附上截图

我的代码:

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import[enter image description here][1] org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;

public class webelements2 {
    public static void main(String[] args) throws InterruptedException
    {
        System.setProperty("webdriver.gecko.driver","C:\\Users\\rpremala003\\Downloads\\geckodriver-v0.14.0-win64\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.carmax.com/");
        Actions builder = new Actions(driver);
        WebElement menuElement = driver.findElement(By.linkText("CARS FOR SALE")).click();
        builder.moveToElement(menuElement).build().perform();
        driver.findElement(By.linkText("Buying from CarMax")).click();      
    }       
}
.click()
不返回元素,您正在尝试将
分配给
。click()
结果分配给
WebElement
。只需删除
。单击()
,它就会正常工作

WebElement menuElement = driver.findElement(By.linkText("CARS FOR SALE")).click();
应该是

WebElement menuElement = driver.findElement(By.linkText("CARS FOR SALE"));