首页 > 解决方案 > 编译时显示的错误消息“未定义类型 RelativeLocators 的方法 withTagName(String)”

问题描述

在编译时,我在 Eclipse 中运行以下程序时收到错误“对于类型 RelativeLocators 的方法 withTagName(String) 未定义”,即使 selenium 版本是“selenium-java-4.0.0-beta-4”和另一个第 5 条导入语句显示错误“无法解析导入 org.openqa.selenium.support.locators.RelativeLocator.withTagName”

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.withTagName;

public class RelativeLocators {

    public static void main(String[] args) {

        WebDriver driver = new ChromeDriver();
        driver.get("rahulshettyacadmy.com/angularpractice");
        WebElement editbox = driver.findElement(By.cssSelector("[name='name']"));
        driver.findElement(withTagName("input").above(editbox).getText());
        WebElement dobleabel = driver.findElement(By.cssSelector("[for='dateofbirth']"));
        driver.findElement(withTagName("input").below(dobleabel)).sendKeys("02/02/1993");
        WebElement iceCreams = driver.findElement(By.xpath("//label[text()='Check me out if you Love IceCreams!']"));
        driver.findElement(withTagName("input").toLeftOf(iceCreams)).click();
        WebElement radiobutton = driver.findElement(By.id("inlineRadio1']"));
System.out.println(driver.findElement(withTagName("input").toRightOf(radiobutton)).getText());
        
    }

}

标签: javaseleniumselenium-webdriver

解决方案


您在 Selenium 插件中有 getTagName 方法,但没有 withTagName ...


推荐阅读