skip to Main Content

I have python code and I need it to pass divs and get text from each div.

I have a loop, which looks like:

for i in range(friends_count):
    found = WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div[class*=friends_list_bl]>div")))

(found is the highlighted div)

(It pass each div, I`ll show you only one)

Here you see one div (highlighted) of the list of divs. I need to take "Гимназия № 82" from here. (Where "class=friends_field").
Here you see one div (highlighted) of the list of divs

I also have a similar code but it takes names from the divs. It looks like:

name = found[i].find_element(By.CLASS_NAME, "AvatarRich__img").get_attribute("alt")

But I can’t think of any way to implement it with this.

P.S: I just need to make XPATH from the highest div on the screenshot, to the very bottom

Can anyone solve this?

2

Answers


  1. Chosen as BEST ANSWER

    I solved my question by using:

    a = found.text
    if (needed_text in a.split("n"):
    

  2. I’m not sure if I understand you question. If you went to take the div from the bottom using as reference the top div you can use an XPATH as follows:

    for i in range(friends_count):
        found = WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[contains(@class, 'friends_list_bl' )]//div[contains(@class, 'friends_field')]")))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search