0

I'm stuck and need help on investigation and improvement.

I am trying to gather all the <a> tags with Annual Report as their partial text then loop through them since they're originally located inside a table(2nd column per row).

Below is the process that I'm planning to execute:

  • After clicking an <a> tag, a new window would pop up
  • find and get specific values in the new window
  • close the window
  • move to the next element (<a> tag) and repeat

The code below is my current progress, but it is completely not working. I am still unable to click the very first element.

var reportLinks = driver.findElements(By.partialLinkText('Annual Report'));

for(var i = 0; i < reportLinks.length; i++){
    reportLinks[i].click();
}
JPaulPunzalan
  • 417
  • 1
  • 6
  • 20

2 Answers2

0

This is how I would accomplish this

//This will get you how many elements are present
var reportLinks = driver.findElements(By.xpath('//tr/td/a[contains(text(),'Annual Report')]'));

//This will click on each element
for(var i = 0; i < reportLinks.length; i++){
driver.findElement(By.xpath('//tr[' + i + ']/td/a[contains(text(),'Annual Report')]')).click();
}

The reason for this is the Annual Report element is not the parent container the element is.

0

I was able to make it work using the code below:

for (var i = 1; i < 51; i++) { 

    var element = driver.findElement(By.xpath('//*[@id="dataList"]/table/tbody/tr[' + i + ']/td[1]/a'));
    driver.executeScript("arguments[0].click();", element);

}

I just copied the xpath on the page through Google Chrome's Inspect Element feature and passed an argument via executeScript.

You could find out how via this link: Is there a way to get the xpath in google chrome?

Thank you very much!

Community
  • 1
  • 1
JPaulPunzalan
  • 417
  • 1
  • 6
  • 20