[英]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.