Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How does Selenium WebDriver find WebElement

Shulou Source: shulou.com Published: 2022-06-03 07:00:45 10月04日 Update

Here's a summary of several common ways to find page elements from our team code:

(1) through the ID of WebElement

If a WebElement provides ID

(2) search through WebElement's name:

WebElement element = driver.findElement (By.name ("passwd"))

(3) search through WebElement's xpath:

WebElement element = driver.findElement (By.xpath ("/ / input [@ id='passwd-id']"))

(4) search through the style of WebElement:

CheddarGouda

You can find page elements by:

Listcheeses = driver.findElements (By.className ("cheese"))

(5) search through hyperlink text:

Cheese >

Then you can find it like this:

WebElement cheese = driver.findElement (By.linkText ("cheese"))

Tags: Elements can be passed through pages code common text methods styles links Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology Apple vpn Docker