Selenium Webdriver getting a cookie value
The methods for working with cookies are defined in the Selenium::WebDriver::Options - see the API docs.
To access these cookie methods, you need to call the manage
method for the driver:
@browser.manage
To get a cookie based on its name, you need to do:
@browser.manage.cookie_named("configsession")
Note that cookie_named
returns a single cookie that matches. The cookies values are a hash. Therefore, you can get values of the cookie by doing:
cookie = @browser.manage.cookie_named("configsession")
cookie[:name]
#=> "configsession"
If you want to get the name of all the cookies on the page, use the all_cookies
method:
driver.manage.all_cookies.each do |cookie|
puts cookie[:name]
end
Unable to set a cookie of Github using Selenium Webdriver
This cookie is set to ensure that browsers that support SameSite cookies can check to see if a request originates from GitHub.
You will find only this cookie have a different value of Strict
in the sameSite
attribute, others being Lax
. So when you skip this cookie, everything works fine. You can set this cookie separately by adding this code:
driver.add_cookie({'name':'__Host-user_session_same_site','value': 'itsValue','sameSite':'Strict'})
Related Topics
What Orm to Use in One Process Multiple Db Connections Sinatra Application
Pg::Error: Error: Invalid Byte Sequence for Encoding "Utf8": 0Xfc
Rails Generate Controller Gives Me Load Error
Require Ruby File Without .Rb Extension
Using Fork in Windows with Ruby
Why Are My Rspec Tests Failing, But My App Is Working
Ruby - How to Thread Across Cores/Processors
How to Specify a Struct as the Return Value of a Function in Rubyffi
Ruby: Mass Initializing Instance Variables
Net-Ssh and Remote Environment
Gem Install Rails Doesn't Work Due to Openssl/Etimedout in Windows
Validate That String Contains Only Allowed Characters in Ruby
Why Does 'Puts(Nil or 4)' Fail in Ruby