Created
June 6, 2024 07:10
-
-
Save SarahElson/be5fe2314d9ea64e1cf653429c1257cf to your computer and use it in GitHub Desktop.
How To Get Element by Tag Name in Selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package CloudGrid; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebElement; | |
import org.testng.annotations.Test; | |
public class TestFindFirstElementByTagName extends BaseTest { | |
@Test | |
public void testFindFirstElementByTagName() | |
{ | |
// navigate to LambdaTest e-commerce playground | |
System.out.println("Navigating to LambdaTest e-commerce playground"); | |
driver.get("https://ecommerce-playground.lambdatest.io/"); | |
// Fetch the first web element with tag h4 | |
System.out.println("Fetching the first element with tag h4"); | |
WebElement element = driver.findElement(By.tagName("h4")); | |
// print the value of the fetched web element | |
System.out.println("Value of the element with tag h4: " + element.getText()); | |
status = "passed"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment