我是一个初学者。我在这方面没有任何实际经验。上个月,我报名参加了一个Selenium初级到高级课程,在那里我几乎没有什么活动可以动手。
我被困在某个地方。让我解释一下我的问题。
这是活动描述:
RelativeXpathLocator
的URL: http://webapps.tekstac.com/Shopify/
测试程序:
使用模板代码。不要在DriverSetup文件中做任何更改。只在建议的部分添加代码到,使用在DriverSetup()中定义的getWebDriver()方法调用驱动程序。使用xpath定位器识别值'SivaKumar'的web元素并返回它。使用相同的web元素,获取文本并返回。
我为此写的代码:
//Add required imports
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
public class RelativeXpathLocator //DO NOT Change the class Name
{
static WebDriver driver;
static String baseUrl = "http://webapps.tekstac.com/Shopify/";
public WebDriver createDriver() //DO NOT change the method signature
{
DriverSetup ds = new DriverSetup();
return ds.getWebDriver();
//Implement code to create Driver from DriverSetup and return it
}
public WebElement getRelativeXpathLocator(WebDriver driver)//DO NOT change the method signature
{
WebElement l = driver.findElement(By.xpath("//*[@id='tbrow']/td[3]"));
return (l);
/*Replace this comment by the code statement to get the Web element */
/*Find and return the element */
}
public String getName(WebElement element)//DO NOT change the method signature
{
return element.getAttribute("tbrow");
//Get the attribute value from the element and return it
}
public static void main(String[] args){
RelativeXpathLocator pl=new RelativeXpathLocator();
driver = pl.createDriver();
//WebElement les = pl.getRelativeXpathLocator(driver);
//String las = pl.getName(les);
//Add required code
}
}
有点卡在这里了。不知道我在getname或main()中犯了什么错误。
结束部分在编译时抛出错误。显示"无法使用预期的xpath找到名称:但为:
请建议。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
public class RelativeXpathLocator //DO NOT Change the class Name
{
static WebDriver driver;
static String baseUrl = "http://webapps.tekstac.com/Shopify/";
public WebDriver createDriver() //DO NOT change the method signature
{
DriverSetup ds = new DriverSetup();
return ds.getWebDriver();
//Implement code to create Driver from DriverSetup and return it
}
public WebElement getRelativeXpathLocator(WebDriver driver)//DO NOT change the method signature
{
WebElement element = driver.findElement(By.xpath("//tr[@id='tbrow']/td[3]"));
return element;
/*Replace this comment by the code statement to get the Web element */
/*Find and return the element */
}
public String getName(WebElement element)//DO NOT change the method signature
{
return element.getText();
//Get the attribute value from the element and return it
}
public static void main(String[] args){
RelativeXpathLocator pl=new RelativeXpathLocator();
driver = pl.createDriver();
//WebElement les = pl.getRelativeXpathLocator(driver);
//String las = pl.getName(les);
//Add required code
}
}