鼠标悬停在issue_Error上,Message_Can不能从void转换为WebElement。
显示"无法从void转换为WebElement"在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();
}
}
答案 0 :(得分:1)
.click()
未返回元素,而您尝试将.click()
结果分配到WebElement
。只需删除.click()
即可正常运行。
WebElement menuElement = driver.findElement(By.linkText("CARS FOR SALE")).click();
应该是
WebElement menuElement = driver.findElement(By.linkText("CARS FOR SALE"));