How to locate Logout functionality for the below scenario ?

Answered

Hi, I’m doing automation for infibeam.com. I’m stuck at logout functionality. Below is the code I’ve used for logout as per your guide, but it didn’t work. Could you help me how to click that particular element ?

Thank you

 

How to locate Logout functionality for the below scenario ?

Train Asked on August 12, 2014 in Selenium WebDriver.
Add Comment
  • 5 Answer(s)
    Best answer

    i reviewed your code once again  and find that

    WebElement element=driver.findElement(By.linkText(“MY ACCOUNT”));

    Actions action = new Actions(driver);
    action.moveToElement(element).build().perform();

    // i put a thread.sleep after this line what you were doing you were clicking on link and at same time trying to click on the logout ( i guess logout is not visible with in that small time , say time when hover is performed so i put a sleep there)

    Thread.sleep(2000);
    driver.findElement(By.linkText(“Logout”)).click();
    Thread.sleep(3000);
    }

    i hope it will work..

    Vice Professor Answered on August 18, 2014.
    Add Comment

    hi paso

     

    Vice Professor Answered on August 12, 2014.
    Add Comment

    Hi ankit,

    that really works….but when we do the same after logging through facebook or google+ and then we try to logout using above code..,,is not working at all…here, I’m writing scenarios…

    1) login using google+
    2) give control to pop-up window and validate the login
    3) give control to parent window
    4) verify the user home page is displayed..
    5) Logout..

    here, I’ve mentioned steps I’m doing for automation… your code works in simple login and after logout… but didn’t work on social login and logout… I wonder the identity of the webelement is same !!! then, why It gives error…could you try it, please ? here is the code..I’ve used for that…

    package infinium.auto;

    import static org.testng.AssertJUnit.assertTrue;

    import java.util.Iterator;
    import java.util.Set;

    import org.apache.log4j.Logger;
    import org.apache.log4j.xml.DOMConfigurator;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.interactions.Actions;
    import org.testng.Reporter;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.Test;

    public class GooglePlus
    {
    private static Logger Log = Logger.getLogger(GooglePlus.class.getName());
    public WebDriver driver;

    @BeforeTest
    public void Initialize()
    {
    DOMConfigurator.configure(“log4j.xml”);
    //System.setProperty(“webdriver.chrome.driver”, “/home/infibeam/Downloads/chromedriver”);
    driver = new FirefoxDriver();
    Log.info(“Web Driver is Instantiated”);
    driver.manage().window().maximize();
    }

    @Test
    public void socialLoginTwitter() throws InterruptedException
    {
    driver.get(“http://newtest.infibeam.com/Login.action”);
    Log.info(“Website is launched”);
    String window1 = driver.getWindowHandle();
    driver.findElement(By.id(“google”)).click();
    Log.info(“Click is performed on google link”);

    Set<String> s = driver.getWindowHandles();
    Iterator<String> ite = s.iterator();

    while(ite.hasNext())
    {
    String popupHandle = ite.next().toString();
    if(!popupHandle.contains(window1))
    {
    driver.switchTo().window(popupHandle);
    driver.findElement(By.id(“Email”)).sendKeys(“abc@infibeam.net”);
    driver.findElement(By.id(“Passwd”)).sendKeys(“abcdef”);
    driver.findElement(By.id(“signIn”)).click();

    driver.switchTo().window(window1);
    System.out.println(driver.getTitle());
    System.out.println(driver.getCurrentUrl());
    }
    }
    Thread.sleep(2000);
    // assertTrue(isTextPresent(“PRASHANT PATEL”));
    WebElement element=driver.findElement(By.linkText(“MY ACCOUNT”));
    Actions action = new Actions(driver);
    action.moveToElement(element).build().perform();
    driver.findElement(By.linkText(“Logout”)).click();
    Thread.sleep(3000);
    }

    /*@AfterMethod
    public boolean isTextPresent(String txtValue)
    {
    boolean b = false;
    try
    {
    b = driver.getPageSource().contains(txtValue);
    return b;
    }
    catch (Exception e)
    {
    System.out.println(e.getMessage());
    }

    finally
    {
    return b;
    }
    }

    @AfterMethod
    public void driverClose()
    {

    driver.close();
    driver.quit();
    }
    */

    }

    Train Answered on August 18, 2014.
    Add Comment

    hi paso i checked your code and i guess u havent handled this window in your code

    RE: How to locate Logout functionality for the below scenario ?

    you can fix this and let me knw if problem persists

    Vice Professor Answered on August 18, 2014.
    Add Comment

    Oh ! couldn’t get this silly thing !! 😛 By the way, you’re awesome.. It really worked. Thank you. 🙂

    Train Answered on August 19, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.