WebElements can be located with selenium webdriver using XPaths. These are expressions that identify elements on a page based on certain details, such as, if the element contains a specific attribute or has a specific child node.
const query = await driver.findElement(By.xpath("//*[contains(text(), 'Wikipedia')]"))
To explain what the different parts of the xpath in the above statement do:
- // means to select an element descending from the root element
- * means the element can be of any type
- @class means to select an element matching the class attribute of the WebElement.