@@ -46,8 +46,8 @@ two elements that have a class name of "tomatoes" so this method will return the
4646 {{< tab header="Java" >}}
4747WebElement vegetable = driver.findElement(By.className("tomatoes"));
4848 {{< /tab >}}
49- {{< tab header="Python" >}}
50- vegetable = driver.find_element(By.CLASS_NAME, "tomatoes")
49+ {{< tab header="Python" text=true >}}
50+ {{< gh-codeblock path="/examples/python/tests/elements/test_finders.py#L9">}}
5151 {{< /tab >}}
5252 {{< tab header="CSharp" >}}
5353var vegetable = driver.FindElement(By.ClassName("tomatoes"));
@@ -79,9 +79,8 @@ ancestor of the undesired element, then call find element on that object:
7979WebElement fruits = driver.findElement(By.id("fruits"));
8080WebElement fruit = fruits.findElement(By.className("tomatoes"));
8181 {{< /tab >}}
82- {{< tab header="Python" >}}
83- fruits = driver.find_element(By.ID, "fruits")
84- fruit = fruits.find_element(By.CLASS_NAME,"tomatoes")
82+ {{< tab header="Python" text=true >}}
83+ {{< gh-codeblock path="/examples/python/tests/elements/test_finders.py#L9-L10">}}
8584 {{< /tab >}}
8685 {{< tab header="CSharp" >}}
8786IWebElement fruits = driver.FindElement(By.Id("fruits"));
@@ -121,10 +120,8 @@ WebElement shadowHost = driver.findElement(By.cssSelector("#shadow_host"));
121120SearchContext shadowRoot = shadowHost.getShadowRoot();
122121WebElement shadowContent = shadowRoot.findElement(By.cssSelector("#shadow_content"));
123122{{< /tab >}}
124- {{< tab header="Python" >}}
125- shadow_host = driver.find_element(By.CSS_SELECTOR, '#shadow_host')
126- shadow_root = shadow_host.shadow_root
127- shadow_content = shadow_root.find_element(By.CSS_SELECTOR, '#shadow_content')
123+ {{< tab header="Python" text=true >}}
124+ {{< gh-codeblock path="/examples/python/tests/elements/test_finders.py#L21-L22">}}
128125{{< /tab >}}
129126{{< tab header="CSharp" >}}
130127var shadowHost = _ driver.FindElement(By.CssSelector("#shadow_host"));
@@ -160,8 +157,8 @@ For this example, we'll use a CSS Selector:
160157 {{< tab header="Java" >}}
161158WebElement fruit = driver.findElement(By.cssSelector("#fruits .tomatoes"));
162159 {{< /tab >}}
163- {{< tab header="Python" >}}
164- fruit = driver.find_element(By.CSS_SELECTOR,"#fruits .tomatoes")
160+ {{< tab header="Python" text=true >}}
161+ {{< gh-codeblock path="/examples/python/tests/elements/test_finders.py#L34" >}}
165162 {{< /tab >}}
166163 {{< tab header="CSharp" >}}
167164var fruit = driver.FindElement(By.CssSelector("#fruits .tomatoes"));
@@ -190,8 +187,8 @@ references to all fruits and vegetable list items will be returned in a collecti
190187 {{< tab header="Java" >}}
191188List<WebElement > plants = driver.findElements(By.tagName("li"));
192189 {{< /tab >}}
193- {{< tab header="Python" >}}
194- plants = driver.find_elements(By.TAG_NAME, "li")
190+ {{< tab header="Python" text=true >}}
191+ {{< gh-codeblock path="/examples/python/tests/elements/test_finders.py#L44" >}}
195192 {{< /tab >}}
196193 {{< tab header="CSharp" >}}
197194IReadOnlyList<IWebElement > plants = driver.FindElements(By.TagName("li"));
@@ -221,20 +218,8 @@ for (WebElement element : elements) {
221218 System.out.println("Paragraph text:" + element.getText());
222219}
223220 {{< /tab >}}
224- {{< tab header="Python" >}}
225- from selenium import webdriver
226- from selenium.webdriver.common.by import By
227-
228- driver = webdriver.Firefox()
229-
230- # Navigate to Url
231- driver.get("https://www.example.com ")
232-
233- # Get all the elements available with tag name 'p'
234- elements = driver.find_elements(By.TAG_NAME, 'p')
235-
236- for e in elements:
237- print(e.text)
221+ {{< tab header="Python" text=true >}}
222+ {{< gh-codeblock path="/examples/python/tests/elements/test_finders.py#L54-L61" >}}
238223 {{< /tab >}}
239224 {{< tab header="CSharp" >}}
240225using OpenQA.Selenium;
@@ -338,32 +323,8 @@ To achieve this, the parent WebElement is chained with 'findElements' to access
338323 }
339324 }
340325 {{< /tab >}}
341- {{< tab header="Python" >}}
342- from selenium import webdriver
343- from selenium.webdriver.common.by import By
344-
345- driver = webdriver.Chrome()
346- driver.get("https://www.example.com ")
347- ##get elements from parent element using TAG_NAME
348-
349- # Get element with tag name 'div'
350- element = driver.find_element(By.TAG_NAME, 'div')
351-
352- # Get all the elements available with tag name 'p'
353- elements = element.find_elements(By.TAG_NAME, 'p')
354- for e in elements:
355- print(e.text)
356-
357- ##get elements from parent element using XPATH
358- ##NOTE: in order to utilize XPATH from current element, you must add "." to beginning of path
359-
360- # Get first element of tag 'ul'
361- element = driver.find_element(By.XPATH, '//ul')
362-
363- # get children of tag 'ul' with tag 'li'
364- elements = driver.find_elements(By.XPATH, './/li')
365- for e in elements:
366- print(e.text)
326+ {{< tab header="Python" text=true >}}
327+ {{< gh-codeblock path="/examples/python/tests/elements/test_finders.py#L66-L74" >}}
367328 {{< /tab >}}
368329 {{< tab header="CSharp" >}}
369330using OpenQA.Selenium;
@@ -465,17 +426,8 @@ It is used to track (or) find DOM element which has the focus in the current bro
465426 }
466427 }
467428 {{< /tab >}}
468- {{< tab header="Python" >}}
469- from selenium import webdriver
470- from selenium.webdriver.common.by import By
471-
472- driver = webdriver.Chrome()
473- driver.get("https://www.google.com ")
474- driver.find_element(By.CSS_SELECTOR, '[ name="q"] ').send_keys("webElement")
475-
476- # Get attribute of current active element
477- attr = driver.switch_to.active_element.get_attribute("title")
478- print(attr)
429+ {{< tab header="Python" text=true >}}
430+ {{< gh-codeblock path="/examples/python/tests/elements/test_finders.py#L85-L88" >}}
479431 {{< /tab >}}
480432 {{< tab header="CSharp" >}}
481433 using OpenQA.Selenium;
0 commit comments