@@ -46,8 +46,8 @@ two elements that have a class name of "tomatoes" so this method will return the
46
46
{{< tab header="Java" >}}
47
47
WebElement vegetable = driver.findElement(By.className("tomatoes"));
48
48
{{< /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">}}
51
51
{{< /tab >}}
52
52
{{< tab header="CSharp" >}}
53
53
var vegetable = driver.FindElement(By.ClassName("tomatoes"));
@@ -79,9 +79,8 @@ ancestor of the undesired element, then call find element on that object:
79
79
WebElement fruits = driver.findElement(By.id("fruits"));
80
80
WebElement fruit = fruits.findElement(By.className("tomatoes"));
81
81
{{< /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">}}
85
84
{{< /tab >}}
86
85
{{< tab header="CSharp" >}}
87
86
IWebElement fruits = driver.FindElement(By.Id("fruits"));
@@ -121,10 +120,8 @@ WebElement shadowHost = driver.findElement(By.cssSelector("#shadow_host"));
121
120
SearchContext shadowRoot = shadowHost.getShadowRoot();
122
121
WebElement shadowContent = shadowRoot.findElement(By.cssSelector("#shadow_content"));
123
122
{{< /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">}}
128
125
{{< /tab >}}
129
126
{{< tab header="CSharp" >}}
130
127
var shadowHost = _ driver.FindElement(By.CssSelector("#shadow_host"));
@@ -160,8 +157,8 @@ For this example, we'll use a CSS Selector:
160
157
{{< tab header="Java" >}}
161
158
WebElement fruit = driver.findElement(By.cssSelector("#fruits .tomatoes"));
162
159
{{< /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" >}}
165
162
{{< /tab >}}
166
163
{{< tab header="CSharp" >}}
167
164
var 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
190
187
{{< tab header="Java" >}}
191
188
List<WebElement > plants = driver.findElements(By.tagName("li"));
192
189
{{< /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" >}}
195
192
{{< /tab >}}
196
193
{{< tab header="CSharp" >}}
197
194
IReadOnlyList<IWebElement > plants = driver.FindElements(By.TagName("li"));
@@ -221,20 +218,8 @@ for (WebElement element : elements) {
221
218
System.out.println("Paragraph text:" + element.getText());
222
219
}
223
220
{{< /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" >}}
238
223
{{< /tab >}}
239
224
{{< tab header="CSharp" >}}
240
225
using OpenQA.Selenium;
@@ -338,32 +323,8 @@ To achieve this, the parent WebElement is chained with 'findElements' to access
338
323
}
339
324
}
340
325
{{< /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" >}}
367
328
{{< /tab >}}
368
329
{{< tab header="CSharp" >}}
369
330
using OpenQA.Selenium;
@@ -465,17 +426,8 @@ It is used to track (or) find DOM element which has the focus in the current bro
465
426
}
466
427
}
467
428
{{< /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" >}}
479
431
{{< /tab >}}
480
432
{{< tab header="CSharp" >}}
481
433
using OpenQA.Selenium;
0 commit comments