Selenium Java to get the title of a given webpage using the getAttribute() method
Codeaft.java
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; class Codeaft { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "/home/codeaft/drivers/chromedriver"); WebDriver driver = new ChromeDriver(); driver.navigate().to("https://codeaft.github.io/testapp/"); WebElement we = driver.findElement(By.tagName("title")); System.out.println(we.getAttribute("textContent")); driver.close(); } }
Output
Codeaft's TestApp
Comments and Reactions