-
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            mdmintz
          
      
      
        Apr 20, 2024 
      
    
    Replies: 1 comment
-
| The SeleniumBase cookie methods for the  sb.save_cookies(name="cookies.txt")
sb.load_cookies(name="cookies.txt")
sb.delete_all_cookies()  # Duplicate: self.clear_all_cookies()
sb.delete_saved_cookies(name="cookies.txt")
sb.get_saved_cookies(name="cookies.txt")
sb.get_cookie(name)
sb.get_cookies()
sb.add_cookie(cookie_dict)
sb.add_cookies(cookies)For more details on those, see seleniumbase/seleniumbase/fixtures/base_case.py. Note that you have to be on the same origin/domain before you can add cookies to it. This example logs in to a website, saves the cookies, opens a new browser, and loads the cookies to avoid logging in again: """A SeleniumBase test that loads cookies to bypass login."""
from seleniumbase import SB
# Log in to Swag Labs and save cookies
with SB(test=True) as sb:
    sb.open("https://www.saucedemo.com")
    sb.wait_for_element("div.login_logo")
    sb.type("#user-name", "standard_user")
    sb.type("#password", "secret_sauce")
    sb.click('input[type="submit"]')
    sb.highlight("div.inventory_list", loops=6)
    sb.save_cookies(name="cookies.txt")
# Load previously saved cookies to bypass login
with SB(test=True) as sb:
    sb.open("https://www.saucedemo.com")
    sb.load_cookies(name="cookies.txt")
    sb.open("https://www.saucedemo.com/inventory.html")
    sb.highlight("div.inventory_list", loops=12) | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
      Answer selected by
        mdmintz
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
The SeleniumBase cookie methods for the
SB()syntax format:For more details on those, see seleniumbase/seleniumbase/fixtures/base_case.py.
Note that you have to be on the same origin/domain before you can add cookies to it.
This example logs in to a website, saves the cookies, opens a new browser, and loads the cookies to avoid logging in again:
"""A SeleniumBase test that loads cookie…