簡體   English   中英

Selenium Webdriver - 相對 xpath

[英]Selenium Webdriver - Relative xpath

我是 Selenium 的初學者。 我沒有任何動手經驗。 上個月,我報名參加了 Selenium 初級到高級課程,我幾乎沒有可以動手實踐的活動。

我被困在某個地方。 讓我解釋一下我的問題。

這是活動說明:

相對XpathLocator

網址: http ://webapps.tekstac.com/Shopify/

測試程序:

  1. 使用模板代碼。
  2. 不要在 DriverSetup 文件中進行任何更改。
  3. 僅在建議的部分中添加代碼,
  4. 使用 DriverSetup() 中定義的 getWebDriver() 方法調用驅動程序
  5. 使用 xpath 定位器識別值“SivaKumar”的 Web 元素並將其返回。
  6. 使用相同的 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 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
    {
        //Get the attribute value from the element and return it
    }

    public static void main(String[] args){
        RelativeXpathLocator pl=new RelativeXpathLocator();
        //Add required code
        
    }
}

注意:卡在 Public Webelement getRelativeXpathLocator

現在,在我輸入代碼並檢查它是否拋出任何錯誤之后,我能夠看到 expect ")" ";" xpath 行中的錯誤。

我已經努力了幾個小時才能讓它發揮作用,但徒勞無功。

請指教。

謝謝。

錯誤是xpath中的雙引號" ,所以更改xpath

driver.findElement(By.xpath("//*[@id="tbrow"]/td[3]"));

driver.findElement(By.xpath("//*[@id='tbrow']/td[3]"));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM