Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我想读取ul标签下列表标签的内容。但是我';我不能用下面的代码阅读。_Java_Selenium - Fatal编程技术网

Java 我想读取ul标签下列表标签的内容。但是我';我不能用下面的代码阅读。

Java 我想读取ul标签下列表标签的内容。但是我';我不能用下面的代码阅读。,java,selenium,Java,Selenium,网址: 代码列为休耕: try{ //WebElement e1 = driver.findElement(By.cssSelector("#atfResults > ul")); WebElement e1 = driver.findElement(By.id("s-results-list-atf")); System.out.println(e1); List<WebElement> links = e1.findElements(By

网址:

代码列为休耕:

try{

    //WebElement e1 = driver.findElement(By.cssSelector("#atfResults > ul"));
    WebElement e1 = driver.findElement(By.id("s-results-list-atf"));
    System.out.println(e1);

    List<WebElement> links = e1.findElements(By.cssSelector("#atfResults > ul"));;
    for (int i = 1; i < links.size(); i++)
    {
        System.out.println(links.get(i).getText());
    }
    }
    catch(Exception e){
        System.out.println(e.getMessage());
    }
}
试试看{
//WebElement e1=driver.findElement(由.cssSelector(“#atfResults>ul”);
WebElement e1=driver.findElement(By.id(“s-results-list-atf”);
系统输出打印LN(e1);
列表链接=e1.findElements(By.cssSelector(#atfResults>ul));;
对于(int i=1;i

如果有人得到解决方案,请告诉我。

要从
url
”读取ul标签下列表标签(项目名称)的内容,可以使用以下代码块:

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Q45519900_amazon_list 
{

    public static void main(String[] args) 
    {
        System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("start-maximized");
        options.addArguments("disable-infobars");
        options.addArguments("--disable-extensions"); 
        WebDriver driver = new ChromeDriver(options);
        driver.navigate().to("https://www.amazon.in/s/ref=sr_pg_2?rh=n%3A1571271031%2Cn%3A%211571272031%2Cn%3A1968024031%2Cn%3A1968093031%2Cp_n_pct-off-with-tax%3A70-%2Cp_98%3A10440597031&page=2&bbn=1968093031&ie=UTF8&qid=1501915937&lo=apparel");
        List<WebElement> element = driver.findElements(By.xpath("//ul[@id='s-results-list-atf']/li[starts-with(@id, 'result_')]/div/div[@class='a-row a-spacing-none']/div/a/h2"));
        System.out.println("Total items : "+element.size());
        for (WebElement my_element:element)
        {
        String title = my_element.getAttribute("innerHTML");
        System.out.println("Item name is : "+title);
        }

    }

}

如果这能回答您的问题,请告诉我。

欢迎使用堆栈溢出!请阅读我们的文章,帮助你提出一个好问题,从而得到一个好答案。你确定你不会因为试图刮取亚马逊的搜索结果而使事情变得过于复杂吗?我希望使用他们的API会容易得多。谢谢回复。我仍然没有得到产品清单。我已经放弃了上面的代码并写入了我的脚本,但仍然没有找到产品列表。它在代码的下面一行给出null。WebElement all_element=driver.findElement(By.id(“s-results-list-atf”);您的输出与我要查找的完全相同,但上面的代码在我这方面不起作用。仍然需要帮助。这行代码是您提供的代码的一部分。检查我的更新答案。您好,我实现了更新的代码行,但仍然在同一行上得到空值,测试失败。检查我的上次更新,并让我知道状态。
Total items : 48
Item name is : GlobalRang Men's Cotton Formal Shirt
Item name is : Rapphael Men's Full sleeve Casual Shirt
Item name is : Feed Up Pack of 4 Men's Pocket Shirts
Item name is : Rapphael Men's Casual Shirt
Item name is : Arihant Men's Solid Formal Shirt
Item name is : United Colors of Benetton Men's Casual Shirt
Item name is : Mossimo Men's Casual Shirt
Item name is : Urban Nomad Orange Cotton Formal Shirt
Item name is : Men's Cotton Shirt
Item name is : Slub Mens Shirt
Item name is : United Colors of Benetton Men's Casual Shirt
Item name is : Rapphael Men's Casual Shirt
Item name is : Arihant Men's Full Sleeves Regular fit Formal Shirt
Item name is : Arihant Men's Formal Shirt
Item name is : Rapphael Charcoal Grey &amp; Blue color Casual Shirt for men
Item name is : Urban Nomad Yellow Cotton Formal Shirt
Item name is : GlobalRang Men's Cotton Casual Royal Blue Stand Collar Shirt
Item name is : SHADE 45 Men's Premium designed Cotton Full Sleeve Slim fit Orange color Plain…
Item name is : Basics Men's Casual Shirt
Item name is : People Men's Casual Shirt
Item name is : Dennison Men's Casual Shirt
Item name is : IZOD Men's Casual Shirt
Item name is : Deezeno Men's Cotton Shirt
Item name is : Easies Men's Casual Shirt
Item name is : Dennison Men's Formal Shirt
Item name is : Slub Men's Casual Shirt
Item name is : Scott International Men's Premium Cotton Blend Pullover Hoodie Sweatshirt With Zip…
Item name is : Rapphael Men's Full sleeve Casual Shirt
Item name is : United Colors of Benetton Men's Casual Shirt
Item name is : Dennison Men's Casual Shirt
Item name is : Arihant Men's Full Sleeves Regular Fit Striped Poly Cotton Formal Shirt
Item name is : GHPC Men's 100%Cotton Slim Fit Full Sleeves Printed Casual Shirt
Item name is : Basics Men's Casual Shirt
Item name is : Rapphael Green &amp; Black Color Casual Shirt for men
Item name is : Urban Nomad Yellow Cotton Formal Shirt
Item name is : Arihant Men's Formal Shirt
Item name is : Trendy Trotters Pink Fullsleeves Shirt
Item name is : Arihant Men's Full Sleeves Regular fit Formal Shirt
Item name is : Dennison Men's Formal Shirt
Item name is : IZOD Men's Casual Shirt
Item name is : Dennison Men's Casual Shirt
Item name is : GHPC Men's 100%Cotton Slim Fit Full Sleeves Striped Casual Shirt
Item name is : Stylox Bull Printed White Shirt [007
Item name is : Deezeno Men's Cotton Shirt
Item name is : Dennison Men's Formal Shirt
Item name is : People Men's Casual Shirt
Item name is : United Colors of Benetton Men's Casual Shirt
Item name is : Rapphael Orange color Casual Shirt for men