简体   繁体   中英

how to collect the header title of all the reports in the application

在此处输入图片说明 在此处输入图片说明 In this application : task is to click on each report link one by one and get the header title of the report from the report page.

so it verifies that the report opens properly with data.

Since there is no common x path in the all reports, thus
to capture the report heading i applied a generic x path : that gives me list of headings in the report page .....later i collected the heading with zero index, ie. the main header

Problem 1: there are few reports where : this x path has no significance, it locate nothing .....and in these report there exists view button ...clicking on view opens the report

Problem 2: there are few report where heading format is align either in right or left

According to my code : it is difficult to catch them ......there are 4 out of 80 such reports in a slot . where x path gives nothing as shown in attachment According to the code what logic should be applied to catch view .... Using page Factory :

 @FindAll({
    @FindBy(how = How.XPATH, using = ".//table//tr[1]/th")
 })

public List<WebElement> view_ReportPDf_page;

 List<WebElement> lis= namedreportviewlinks;     
 ///// TO get the report links within 
 int count=0;
 for (int j = 0; j < lis.size(); j++) {
 WebElement e2 = lis.get(j);
 ((JavascriptExecutor) 
 driver).executeScript("arguments[0].scrollIntoView(true);",e2);

 e2.click();
 for (String winHandle : driver.getWindowHandles()) 
 {
 driver.switchTo().window(winHandle);
 }
 Thread.sleep(1000);
 List<WebElement> lis2= ld.view_ReportPDf_page;
 for(WebElement headers:lis2)
{
headers=lis2.get(0);
System.out.println(headers.getText()+"--------------------"+count);
break;
}
driver.close();
 count++;
 for (String winHandle : driver.getWindowHandles())
 {
  driver.switchTo().window(winHandle);
 }
 }
 ld.Dnetsubcategoryreport_backbutton.click();

 }
  1. If the View button is present under th tag then findElements() method can be used to check the presence of this button. If present, click on it else click on report link. eg

    if(driver.findElements(By.name("View")).size>0) { //logic to click on View button } else { //click on report link }

  2. If the reports table is the only table on the page, then elements can be located using tagName as th. (NOTE: All report links should be under th tag then this approach can be applied.)

Hope this helps!

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