简体   繁体   中英

Can't get list of objects Selenium Java

source web code

在此处输入图像描述

public static void notifications(){

    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div/div/div/div[2]/header/div/div/div/div[1]/div[2]/nav/a[3]/div/div/div")));
    WebElement notificationButton = driver.findElement(By.xpath("/html/body/div/div/div/div[2]/header/div/div/div/div[1]/div[2]/nav/a[3]/div/div/div"));
    notificationButton.click();

    Array[] posts = (Array[]) driver.findElements(By.xpath("//div[@aria_label='position: relative; min-height: 3681px;']")).toArray();
    System.out.println(posts[0]);
}

I tryed this but it's probably bad. I'm trying to get on console all my notifications from Twitter as a text. Any ideas?

You dont need to use array to hadle your web elements. You can handle list of element as per below with webdrivers:

    List<WebElement> myElements = driver.findElements(By.xpath("some/path//a"));
    System.out.println("Size of List: "+myElements.size());
    for(WebElement element : myElements) 
    {        

        System.out.println("elements: "+element .getText());
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM