我尝试用另一种方法打开链接,但是打开浏览器链接后没有打开,并且在尝试获取机动车变量时,我收到诸如"方法getText((未定义字符串类型"和"类型不匹配:无法从void转换为字符串"之类的错误。
public class ExcelReadData {
WebDriver driver;
public void driverCall()
{
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
}
public void login(String username,String password)
{
driver.get("http://kaefer.ccstechnologies.org/#/login");
driver.findElement(By.xpath("//input[@id='username']")).sendKeys(username);
driver.findElement(By.xpath("//input[@id='password']")).sendKeys(password);
driver.findElement(By.xpath("//button[@class='btn btn-lg btn-primary btn-block primary-button']")).click();
}
public void addHireFromMotorVehicleOwn(String motorvehicle)
{
driver.findElement(By.xpath("//*[@id='add-vehicle']")).click();//click on add vehicle
driver.findElement(By.xpath("(//*[@class='mat-radio-inner-circle'])[1]")).click();//click on own radio button
//1st value
driver.findElement(By.xpath("//mat-form-field[@id='vehicleCategoryOwn']")).click();//click on dropdown value
String motorvehiclename1= driver.findElement(By.xpath("//mat-option[@id='Pickup']")).click();//click on pickup from dropdown
motorvehiclename1.getText()
}}
而不是
String motorvehiclename1=driver.findElement(By.xpath("//matoption[@id='Pickup']")).click();
它应该是
WebElement motorvehiclename1=driver.findElement(By.xpath("//matoption[@id='Pickup']"));
机动车名称1.getText((;
因为 findElement 方法返回的是 webelement 而不是字符串。