diff --git a/examples/python/tests/interactions/test_cookies.py b/examples/python/tests/interactions/test_cookies.py index 53b695b6fc83..779965a8a332 100644 --- a/examples/python/tests/interactions/test_cookies.py +++ b/examples/python/tests/interactions/test_cookies.py @@ -1,2 +1,71 @@ from selenium import webdriver + +def add_cookie(): + driver = webdriver.Chrome() + driver.get("http://www.example.com") + + # Adds the cookie into current browser context + driver.add_cookie({"name": "key", "value": "value"}) + + +def get_named_cookie(): + driver = webdriver.Chrome() + driver.get("http://www.example.com") + + # Adds the cookie into current browser context + driver.add_cookie({"name": "foo", "value": "bar"}) + + # Get cookie details with named cookie 'foo' + print(driver.get_cookie("foo")) + + +def get_all_cookies(): + driver = webdriver.Chrome() + + driver.get("http://www.example.com") + + driver.add_cookie({"name": "test1", "value": "cookie1"}) + driver.add_cookie({"name": "test2", "value": "cookie2"}) + + # Get all available cookies + print(driver.get_cookies()) + +def delete_cookie(): + driver = webdriver.Chrome() + + driver.get("http://www.example.com") + + driver.add_cookie({"name": "test1", "value": "cookie1"}) + driver.add_cookie({"name": "test2", "value": "cookie2"}) + + # Delete cookie with name 'test1' + driver.delete_cookie("test1") + + +def delete_all_cookies(): + driver = webdriver.Chrome() + + driver.get("http://www.example.com") + + driver.add_cookie({"name": "test1", "value": "cookie1"}) + driver.add_cookie({"name": "test2", "value": "cookie2"}) + + # Delete all cookies + driver.delete_all_cookies() + + +def same_side_cookie_attr(): + driver = webdriver.Chrome() + + driver.get("http://www.example.com") + + # Adds the cookie into current browser context with sameSite 'Strict' (or) 'Lax' + driver.add_cookie({"name": "foo", "value": "value", "sameSite": "Strict"}) + driver.add_cookie({"name": "foo1", "value": "value", "sameSite": "Lax"}) + + cookie1 = driver.get_cookie("foo") + cookie2 = driver.get_cookie("foo1") + + print(cookie1) + print(cookie2) diff --git a/website_and_docs/content/documentation/webdriver/interactions/cookies.en.md b/website_and_docs/content/documentation/webdriver/interactions/cookies.en.md index abbfd2aacc85..7346e36eabf1 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/cookies.en.md +++ b/website_and_docs/content/documentation/webdriver/interactions/cookies.en.md @@ -31,14 +31,7 @@ e.g. http://example.com/some404page) {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L30-L32" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -driver.get("http://www.example.com") - -# Adds the cookie into current browser context -driver.add_cookie({"name": "key", "value": "value"}) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L5-L9" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L32-L34" >}} @@ -87,18 +80,7 @@ It returns the serialized cookie data matching with the cookie name among all as {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L38-L42" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") - -# Adds the cookie into current browser context -driver.add_cookie({"name": "foo", "value": "bar"}) - -# Get cookie details with named cookie 'foo' -print(driver.get_cookie("foo")) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L13-L20" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L40-L44" >}} @@ -151,18 +133,7 @@ If browser is no longer available it returns error. {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L52-L66" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") - -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Get all available cookies -print(driver.get_cookies()) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L24-L32" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L51-L64" >}} @@ -217,16 +188,7 @@ It deletes the cookie data matching with the provided cookie name. {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L74-L77" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Delete a cookie with name 'test1' -driver.delete_cookie("test1") +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L35-L43" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L70-L73" >}} @@ -284,16 +246,7 @@ It deletes all the cookies of the current browsing context. {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L100-L105" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Deletes all cookies -driver.delete_all_cookies() +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L47-L55" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L92-L97" >}} @@ -381,18 +334,7 @@ public class cookieTest { } {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -driver.get("http://www.example.com") -# Adds the cookie into current browser context with sameSite 'Strict' (or) 'Lax' -driver.add_cookie({"name": "foo", "value": "value", 'sameSite': 'Strict'}) -driver.add_cookie({"name": "foo1", "value": "value", 'sameSite': 'Lax'}) -cookie1 = driver.get_cookie('foo') -cookie2 = driver.get_cookie('foo1') -print(cookie1) -print(cookie2) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L59-L71" >}} {{< /tab >}} {{< tab header="CSharp" >}} using OpenQA.Selenium; diff --git a/website_and_docs/content/documentation/webdriver/interactions/cookies.ja.md b/website_and_docs/content/documentation/webdriver/interactions/cookies.ja.md index 9f18d5e09242..da5724a1f849 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/cookies.ja.md +++ b/website_and_docs/content/documentation/webdriver/interactions/cookies.ja.md @@ -28,14 +28,7 @@ Cookieの追加では、一連の定義済みのシリアル化可能なJSONオ {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L30-L32" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -driver.get("http://www.example.com") - -# Adds the cookie into current browser context -driver.add_cookie({"name": "key", "value": "value"}) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L5-L9" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L32-L34" >}} @@ -83,18 +76,7 @@ fun main() { {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L38-L42" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") - -# Adds the cookie into current browser context -driver.add_cookie({"name": "foo", "value": "bar"}) - -# Get cookie details with named cookie 'foo' -print(driver.get_cookie("foo")) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L13-L20" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L40-L44" >}} @@ -146,18 +128,7 @@ fun main() { {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L52-L66" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") - -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Get all available cookies -print(driver.get_cookies()) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L24-L32" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L51-L64" >}} @@ -211,16 +182,7 @@ fun main() { {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L74-L77" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Delete a cookie with name 'test1' -driver.delete_cookie("test1") +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L35-L43" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L70-L73" >}} @@ -277,16 +239,7 @@ fun main() { {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L100-L105" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Deletes all cookies -driver.delete_all_cookies() +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L47-L55" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L92-L97" >}} @@ -371,18 +324,7 @@ public class cookieTest { } {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -driver.get("http://www.example.com") -# Adds the cookie into current browser context with sameSite 'Strict' (or) 'Lax' -driver.add_cookie({"name": "foo", "value": "value", 'sameSite': 'Strict'}) -driver.add_cookie({"name": "foo1", "value": "value", 'sameSite': 'Lax'}) -cookie1 = driver.get_cookie('foo') -cookie2 = driver.get_cookie('foo1') -print(cookie1) -print(cookie2) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L59-L71" >}} {{< /tab >}} {{< tab header="CSharp" >}} using OpenQA.Selenium; diff --git a/website_and_docs/content/documentation/webdriver/interactions/cookies.pt-br.md b/website_and_docs/content/documentation/webdriver/interactions/cookies.pt-br.md index 820651be031e..ab5cda4e4cda 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/cookies.pt-br.md +++ b/website_and_docs/content/documentation/webdriver/interactions/cookies.pt-br.md @@ -30,14 +30,7 @@ por exemplo http://example.com/some404page) {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L30-L32" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -driver.get("http://www.example.com") - -# Adds the cookie into current browser context -driver.add_cookie({"name": "key", "value": "value"}) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L5-L9" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L32-L34" >}} @@ -85,18 +78,7 @@ Retorna os dados do cookie serializado correspondentes ao nome do cookie entre t {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L38-L42" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") - -# Adds the cookie into current browser context -driver.add_cookie({"name": "foo", "value": "bar"}) - -# Get cookie details with named cookie 'foo' -print(driver.get_cookie("foo")) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L13-L20" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L40-L44" >}} @@ -148,18 +130,7 @@ Se o navegador não estiver mais disponível, ele retornará um erro. {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L52-L66" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") - -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Get all available cookies -print(driver.get_cookies()) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L24-L32" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L51-L64" >}} @@ -213,16 +184,7 @@ Exclui os dados do cookie que correspondem ao nome do cookie fornecido. {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L74-L77" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Delete a cookie with name 'test1' -driver.delete_cookie("test1") +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L35-L43" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L70-L73" >}} @@ -279,16 +241,7 @@ Exclui todos os cookies do contexto de navegação atual. {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L100-L105" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Deletes all cookies -driver.delete_all_cookies() +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L47-L55" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L92-L97" >}} @@ -375,18 +328,7 @@ public class cookieTest { } {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -driver.get("http://www.example.com") -# Adds the cookie into current browser context with sameSite 'Strict' (or) 'Lax' -driver.add_cookie({"name": "foo", "value": "value", 'sameSite': 'Strict'}) -driver.add_cookie({"name": "foo1", "value": "value", 'sameSite': 'Lax'}) -cookie1 = driver.get_cookie('foo') -cookie2 = driver.get_cookie('foo1') -print(cookie1) -print(cookie2) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L59-L71" >}} {{< /tab >}} {{< tab header="CSharp" >}} using OpenQA.Selenium; diff --git a/website_and_docs/content/documentation/webdriver/interactions/cookies.zh-cn.md b/website_and_docs/content/documentation/webdriver/interactions/cookies.zh-cn.md index f559bc9ddf55..4275daf24f82 100644 --- a/website_and_docs/content/documentation/webdriver/interactions/cookies.zh-cn.md +++ b/website_and_docs/content/documentation/webdriver/interactions/cookies.zh-cn.md @@ -26,14 +26,7 @@ WebDriver API提供了一种使用内置的方法与Cookie进行交互: {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L30-L32" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -driver.get("http://www.example.com") - -# Adds the cookie into current browser context -driver.add_cookie({"name": "key", "value": "value"}) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L5-9" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L32-L34" >}} @@ -81,18 +74,7 @@ fun main() { {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L38-L42" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") - -# Adds the cookie into current browser context -driver.add_cookie({"name": "foo", "value": "bar"}) - -# Get cookie details with named cookie 'foo' -print(driver.get_cookie("foo")) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L13-L20" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L40-L44" >}} @@ -143,18 +125,7 @@ fun main() { {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L52-L66" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") - -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Get all available cookies -print(driver.get_cookies()) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L24-L32" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L51-L64" >}} @@ -208,16 +179,7 @@ fun main() { {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L74-L77" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Delete a cookie with name 'test1' -driver.delete_cookie("test1") +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L35-L43" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L70-L73" >}} @@ -274,16 +236,7 @@ fun main() { {{< gh-codeblock path="examples/java/src/test/java/dev/selenium/interactions/CookiesTest.java#L100-L105" >}} {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver -driver = webdriver.Chrome() - -# Navigate to url -driver.get("http://www.example.com") -driver.add_cookie({"name": "test1", "value": "cookie1"}) -driver.add_cookie({"name": "test2", "value": "cookie2"}) - -# Deletes all cookies -driver.delete_all_cookies() +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L47-L55" >}} {{< /tab >}} {{< tab header="CSharp" text=true >}} {{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/CookiesTest.cs#L92-L97" >}} @@ -369,18 +322,7 @@ public class cookieTest { } {{< /tab >}} {{< tab header="Python" >}} -from selenium import webdriver - -driver = webdriver.Chrome() - -driver.get("http://www.example.com") -# Adds the cookie into current browser context with sameSite 'Strict' (or) 'Lax' -driver.add_cookie({"name": "foo", "value": "value", 'sameSite': 'Strict'}) -driver.add_cookie({"name": "foo1", "value": "value", 'sameSite': 'Lax'}) -cookie1 = driver.get_cookie('foo') -cookie2 = driver.get_cookie('foo1') -print(cookie1) -print(cookie2) +{{< gh-codeblock path="examples/python/tests/interactions/test_cookies.py#L59-L71" >}} {{< /tab >}} {{< tab header="CSharp" >}} using OpenQA.Selenium;