Search⌘ K
AI Features

Getting Link Attributes and Tabs Switching

Explore how to identify and extract attributes from hyperlinks using Selenium WebDriver in Node.js. Understand methods to handle links that open new browser tabs or windows, and learn techniques for switching between tabs to ensure comprehensive web testing.

Getting link data attributes

Selenium provides functionality not only for driving the link, but also for driving its attributes. To do this, we first need to identify the link. Once it is identified, we can get to its other attributes (this generally applies to most of the web controls). The following script shows how to get data attributes of a link:

driver.findElement(By.linkText("Recommend Selenium")).getAttribute("href").then(  
  function(the_href) {
    assert(the_href.contains("/site/index.html"))
});
driver.findElement(By.linkText("Recommend Selenium")).getAttribute("id").then(funct
...