1

I looked at multiple sources on the web. For example, https://www.guru99.com/handling-cookies-selenium-webdriver.html Nothing works as they describe. After adding cookies with driver.manage().addCookie(ck), you still stay on the login page. Could you, please provide, at least one working example on how to bypass the login screen to speed up the test execution suite in WebDriver Java?

8
  • 1
    I think you want to set Selenium to use a profile that is already logged-in/remembered. It's going to depend on the site's authorization, but some will use sessions cookies which are tied to a profile. Commented Jul 1, 2020 at 22:10
  • @pcalkins Could you provide a code sample? Thanks Commented Jul 1, 2020 at 22:44
  • 1
    There's a post here about Chromedriver: stackoverflow.com/questions/14480717/… And Firefox here: stackoverflow.com/questions/52464598/… I don't think you can set one for IE/Edge. Commented Jul 1, 2020 at 22:50
  • @pcalkins, I could not find anything about adding cookies to ChromeOptions to bypass login in the links you provided. Could you please elaborate? Commented Jul 1, 2020 at 23:24
  • 1
    You have to navigate the driver to demo.guru99.com/test/cookie/selenium_cookie.php to check the cookie. Commented Jul 3, 2020 at 6:42

2 Answers 2

1

I misunderstood the process. The sources I used all copy the same error. Thank you to @pburgr for the hint. The correct process is

  1. Login to the site with your username and password to record the cookies into the file.
  2. Open login page to get the domain cookies.
  3. Add cookies from the file to your request and go to the home page bypassing login process. In the code that is available on the web, they go to the login page in step 3 instead of the home page.
Sign up to request clarification or add additional context in comments.

Comments

0

as Vladimir said:

driver.get("http://demo.guru99.com/test/cookie/selenium_aut.php"); //read cookies from file and add it to browser driver.manage().addCookie(cookie); driver.navigate().refresh(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.