Answer the question
In order to leave comments, you need to log in
How to correctly write css_selector of an element from a set of elements in the WebDriverWait method?
I have some sheet with elements:
example_list = self.driver.find_elements_by_css_selector("div.holder")
example_list.find_element_by_css_selector("i.icon")
WebDriverWait(self.driver, 10).until()
Answer the question
In order to leave comments, you need to log in
@fandorin_official
try creating a class that
takes both locators and does both lookups:
class waittest:
def __init__(self, locator1, locator2, attr, value):
self._locator1 = locator1
self._locator2 = locator2
self._attribute = attr
self._attribute_value = value
def __call__(self, driver):
element1 = driver.find_element_by_xpath(self._locator1)
# опущена проверка что element1 хороший
element2 = element1.find_element_by_xpath(self._locator2)
if element2.get_attribute(self._attribute) == self._attribute_value:
return element2
else:
return None
driver = webdriver.Firefox()
driver.get('http://www.ubuntu.com/')
try:
element = WebDriverWait(driver, 10).until(
waittest('//*[@id="navigation"]/div/div/div','a[@href="/"]', 'class', 'p-navigation__link')
)
if element != None:
print element.get_attribute('innerHTML')
except TimeoutException:
pass
driver.close()
driver.quit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question