0

I have some problems with Selenium where I am trying to find all elements and then try to use WebDriverWait:

WebDriverWait(browser, 5).until(
    EC.presence_of_element_located((By.XPATH,
                                    "//*[contains(text(), 'Hello')]")))
getAllErrors = WebDriverWait(browser, 5).until(
    EC.presence_of_all_elements_located((By.CLASS_NAME, "message")))

for productErrors in getAllErrors:

    if 'Sad moments' in productErrors.text:

        totalProduct = WebDriverWait(browser, 5).until(
            EC.presence_of_element_located((productErrors.find_element_by_xpath("//input[@type='number']"))))

        #How to call productErrors and to use WebDriverWait with it?

I wonder how to use the for loop data and use WebDriverWait with the for loop varaiable?

Basically something like

for productErrors in getAllErrors:

    WebDriverWait(browser, 5).until(EC.presence_of_element_located((productErrors.find_element_by_xpath("//input[@type='number']")))) 
    #Use productErrors For loop and find the xpath from productErrors

1 Answer 1

3

There is no presence_of for already located element, but you can use visibility_of

wait = WebDriverWait(browser, 5)
for productErrors in getAllErrors:
    wait.until(EC.visibility_of(productErrors.find_element_by_xpath("./following-sibling::div//input[@type='number']")))

Don't forget to add . to the xpath for context search. You can also declare WebDriverWait(browser, 5) one time and use it everywhere.

Sign up to request clarification or add additional context in comments.

8 Comments

You can use presence_of_element_located here as well.
@Murthi presence_of_element_located receive By as parameter, not WebElement.
Is it possible to do wait = WebDriverWait(productErrors, 5) instead of browser?
@Thrillofit86 No, WebDriverWait __init__ expects WebDriver. Why? what are trying to do by doing that?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.