I want to verify a text in the footer. I normally copied the XPath locator and find element then get the text of the element, but nothing happens for this code part in Junit.
From this website I need to get the footer text:
Here is the code I am using for this. I know there is another way of doing it.
public class QAA_mock3 {
private WebDriver driver;
private Map<String, Object> vars;
JavascriptExecutor js;
@Before
public void setUp() {
driver = utils.HelperFunctions.createAppropriateDriver("Chrome");
js = (JavascriptExecutor) driver;
vars = new HashMap<String, Object>();
}
@Test
public void test() {
String ExpTitle = "QAAgility" ;
Actions actions = new Actions(driver);
By TwitterLink = By.xpath("//*[@id=\"custom_html-4\"]/div/div[1]/a[2]");
By footer = By.xpath("//div[@id='footer']");
By imglogo = By.cssSelector("img.header-image");
driver.get(" https://www.qaagility.com");
System.out.println("Loaded page...");
String ActTitle = driver.getTitle();
System.out.println("page Title..."+ ActTitle);
if(ActTitle.contains(ExpTitle)) {
System.out.println("Verified the title for ..."+ ExpTitle);
}
else
System.out.println("Title verification went wrong...");
WebElement imgSize = driver.findElement(imglogo);
Dimension imageSize = imgSize.getSize();
int Height = imageSize.getHeight();
int Width = imageSize.getWidth();
System.out.println("The size of the Logo is : Width = "+ Width + "; Height = "+Height);
WebElement Twitter = driver.findElement(TwitterLink);
String Href = Twitter.getAttribute("href");
System.out.println("Twitter Link is :"+ Href);
WebElement footerText = driver.findElement(footer);
System.out.println("WebElement for footer is"+ footerText);
actions.moveToElement(footerText).build().perform();
String FTText = footerText.getText();
System.out.println("Footer Text is :"+ FTText);
}
@After
public void tearDown() throws Exception {
driver.quit();
}
}
You wrong define footer locator:
By footer = By.xpath("//div[@id='footer']");
Try this:
By footer = By.className("copyright-bar")