F
F
fandorin_official2020-01-14 09:07:29
Python
fandorin_official, 2020-01-14 09:07:29

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")

In it, I'm looking for the element I need:
example_list.find_element_by_css_selector("i.icon")

This element must be clickable.
How to correctly enter this element into the waiting: If you just needed to find the element by id or another parameter, the question would not arise. And then an element from an element ...
WebDriverWait(self.driver, 10).until()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergey, 2020-01-15
kuzmin @sergueik

@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()

will print the ubuntu logo (svg). EMNIP in Java the same problem with the signature

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question