简体   繁体   English

如何使用Selenium WebDriver在表的div标记中获取值

[英]How to get the value inside a div tag in a table using selenium webdriver

I am trying to do automation for one of my application using selenium webdriver. 我正在尝试使用Selenium Webdriver为我的一个应用程序进行自动化。 The problem is I am trying to fetch the data from table which contains the value inside a "div" tag.The table is nothing but a calendar. 问题是我试图从包含“ div”标记内的值的表中获取数据。该表不过是一个日历。

This is my code for fetching the value from table.(ie,div tag) 这是我从表中获取值的代码。(即div标签)

public boolean webElement_Table_findCellValue_WD(String locatorType, String locatorVal, String cellText){
    boolean elementStatus = false;  
    WebElement tbl = this.getWebElement(locatorType, locatorVal);

    List<WebElement> tbTag=tbl.findElements(By.tagName("table"));

    int num=tbTag.size();
    System.out.println("hhhhhhhhhhhhhhhhhhh"+num);

    for(WebElement tbTagEle: tbTag)
    {
        List<WebElement> trTag=tbTagEle.findElements(By.tagName("tr"));
        System.out.println("iiiiiiiiiiiiii"+trTag.size());

        for(WebElement trTagEle: trTag)
        {
            List<WebElement> tdTag=trTagEle.findElements(By.tagName("td"));
            System.out.println("jjjjjjjjjjjjj"+tdTag.size());
            for(WebElement tdTagEle: tdTag)
            {
                List<WebElement> divTag=tdTagEle.findElements(By.tagName("div"));
                for(WebElement divTagEle: divTag)
                System.out.println("the contents are:"+divTagEle.getText());
            }
        }
    }

    return elementStatus;   

}

My intention is just to select(click) a date from the calender.(Table) which I will pass it through a properties file. 我的目的只是从日历中选择(单击)日期。(表)将其通过属性文件传递。

In answer to the first part of the question, @Striter Alfa got most of the way. 在回答问题的第一部分时,@ Striter Alfa掌握了大部分方法。

The following will print the content of each <div> within each cell within each table (whether one or multiple): 下面将打印每个表(无论是一个还是多个)中每个单元格中每个<div>的内容:

for (WebElement elem : driver.findElements(By.cssSelector("table td div"))) {
    System.out.println("Each div:" + elem.getText());
}

I don't know whether you need to store those values in a List . 我不知道您是否需要将这些值存储在List The rest of your question isn't very clear, but hopefully you will be able to solve it from here. 您的其余问题不是很清楚,但是希望您可以从这里解决。

The following will find the specific date table and click on the same.pass date value as parameter. 下面将找到特定的日期表,然后单击same.pass日期值作为参数。 WebElement el = driver.findElement(By.xpath("//table//div[contains(.,'"+date+"')]")) el.click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Java使用Selenium Webdriver在此html中获取标记值? - How to get the <b> tag value in this html with Selenium Webdriver using Java? On Selenium WebDriver 如何从带标记标签的 div 中获取文本 - On Selenium WebDriver how to get Text from div with Mark Tag 如何使用Selenium WebDriver Java从标签内部获取文本? - How to get text from inside tag use selenium webdriver java? 如何使用 selenium webDriver 列出标签内的所有内容 - How to list all the <td> inside the <tr> tag using selenium webDriver 如何从中获取价值 <h3> Java Selenium WebDriver中的标记 - How to get value from <h3> tag in Selenium WebDriver, Java 如何从中获取价值<h1>在 Selenium WebDriver、Java 中使用类标记 - How to get value from <h1> tag using class in Selenium WebDriver, Java 如何在Java中使用Selenium在div中获取锚标记href和锚标记文本 - How to get anchor tag href and anchor tag text inside a div using Selenium in Java 如何使用Java获取段落标记。(div / div / p)中的文本(用于硒自动化) - How to get the text inside a paragraph tag .(div/div/p) using Java(for selenium automation) 如何使用Selenium在标头标签中获取锚标签值和href值 - How to get the anchor tag value and href value inside a header tag using selenium 如何使用Selenium Webdriver从以下div获取文本 - How to get a text from following div using Selenium Webdriver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM