You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, there is a tiny mistake on page /documentation/webdriver/elements/finders/
# Get first element of tag 'ul'
element = driver.find_element(By.XPATH, '//ul')
# get children of tag 'ul' with tag 'li'
elements = driver.find_elements(By.XPATH, './/li')
# actually should be, if you really need children
elements = element.find_elements(By.XPATH, './/li')
Here it is my example demonstrating mistake:
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://www.selenium.dev/selenium/web/draggableLists.html")
element = driver.find_element(By.XPATH, "//ul[2]")
print (" Correct way: use element")
elements = element.find_elements(By.XPATH, ".//li")
for e in elements:
print(e.text)
print ("\n Incorrect way: use driver")
elements2 = driver.find_elements(By.XPATH, ".//li")
for e2 in elements2:
print(e2.text)
driver.quit()
It gives
./subelements.py
Correct way: use element
RightItem 1
RightItem 2
RightItem 3
RightItem 4
RightItem 5
So, 'driver' is top-level object relating to whole web-page. But if you need children li elements of ul, you need to use 'element' instead of 'driver'.
PS: for your html code provided on that page of documentation that works, because there is only one tag ul. But that page, that I used, tere are two ul's, so for certain relation need to use that 'element' you got on first step, instead of 'driver'.
Thank you!
The text was updated successfully, but these errors were encountered:
Hello, there is a tiny mistake on page /documentation/webdriver/elements/finders/
Here it is my example demonstrating mistake:
It gives
./subelements.py
Correct way: use element
RightItem 1
RightItem 2
RightItem 3
RightItem 4
RightItem 5
Incorrect way: use driver
LeftItem 1
LeftItem 2
LeftItem 3
LeftItem 4
LeftItem 5
RightItem 1
RightItem 2
RightItem 3
RightItem 4
RightItem 5
So, 'driver' is top-level object relating to whole web-page. But if you need children li elements of ul, you need to use 'element' instead of 'driver'.
PS: for your html code provided on that page of documentation that works, because there is only one tag ul. But that page, that I used, tere are two ul's, so for certain relation need to use that 'element' you got on first step, instead of 'driver'.
Thank you!
The text was updated successfully, but these errors were encountered: