Darshit Shah
Darshit Shah

Reputation: 90

Unable to access method from outside of class

I have two .java files, one file (StockWatchlistElements.java) I have declare all the elements of the page and on second file (Example.java) I used that element.

StockWatchlistElements.java

public static WebElement lnkaStockWatchlist(WebDriver driver) {
        try {
            element = driver.findElements(By.xpath("//*[@id=\"dnn_ctr769_StockWatchList_pnlContent\"]/table/tbody/tr"));
        } catch (Exception e) {
            throw (e);
        }
        return element;
    }

Example.java

List<WebElement> rows = StockWatchlistElements.lnkaStockWatchlist(driver);
        int count = rows.size();
        System.out.println("ROW COUNT : " + count);

Upvotes: 0

Views: 125

Answers (1)

Mustahsan
Mustahsan

Reputation: 3862

change your method definition from WebElement to List<WebElement> like:

public static List<WebElement> lnkStockWatchlist(WebDriver driver) {
        List<WebElement> element = new ArrayList<>();
        try {
            element = driver.findElements(By.xpath("//*[@id=\"dnn_ctr769_StockWatchList_pnlContent\"]/table/tbody/tr"));
        } catch (Exception e) {
            throw (e);
        }
        return element;
    }

Upvotes: 2

Related Questions