1

After the code clicks the action to login, the page gets refreshed and doesn't redirect to the next page. This only occurs for this website as I am redirected properly on other sites. When I am giving the wrong credentials even the error message is not getting displayed.(Manually it works)

I am testing in Chrome with Selenium java.

Here is my code:

public class Test {

    private static final String HTMLPageSourceCode = null;

    public static void main(String[] args) throws InterruptedException   
    {
       System.setProperty("webdriver.chrome.driver","C:\\Selenium project\\chromedriver_win32/chromedriver.exe");
       WebDriver driver = new ChromeDriver();
       driver.manage().window().maximize();

       driver.get("https://-----/tandem/login");

       Thread.sleep(5000);

       driver.manage().deleteAllCookies();

       driver.findElement(By.id("login")).sendKeys("----");
       driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);  

       driver.findElement(By.id("password")).sendKeys("----");

       WebElement loginbutton = driver.findElement(By.xpath(".//*[@id='login-button']"));
       Actions actions = new Actions(driver);  
       actions.click(loginbutton).perform();

   }

}
sandy
  • 29
  • 6
  • could You provide the link to the webpage You're trying to conduct login on? – eugene.polschikov Jul 18 '19 at 14:43
  • Are You sure You did find all locators: xpath elements correctly? – eugene.polschikov Jul 18 '19 at 14:43
  • 1
    Why do you need to use action class where you can only use `loginbutton.click()` – KunduK Jul 18 '19 at 14:45
  • In addition to KunduK's comment, if you're going to use implicit wait you should use it before accessing any web elements (just once). Also, since you're using sleep after page load, why aren't you also using sleep after your attempted actions click? How are you even seeing a screen refresh since the click is the last statement? – Bill Hileman Jul 18 '19 at 14:48
  • https://outhouse.inhouseusa.com/tandem/login/? is the link. – sandy Jul 18 '19 at 15:27
  • I tried all the locators – sandy Jul 18 '19 at 15:28
  • I used action class as i was trying many possibilities and this worked for me. – sandy Jul 18 '19 at 15:30
  • What i understood is that the screen is refreshing as the session is not lasting for some time.Thank you for the quick replay guys. – sandy Jul 18 '19 at 15:31

1 Answers1

1

To login in into the website https://outhouse.inhouseusa.com/tandem/login/ you need to induce WebDriverWait for the elementToBeClickable() and you can use the following Locator Strategies:

  • Code Block:

    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    //options.addArguments("disable-infobars");
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://outhouse.inhouseusa.com/tandem/login/");
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.form-control#login"))).sendKeys("sandy");
    driver.findElement(By.cssSelector("input.form-control#password")).sendKeys("sandy");
    driver.findElement(By.cssSelector("input.pull-right.button.button-primary#login-button")).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352