Extract text from an aria-label selenium webdriver (python)

前端 未结 1 1059
执念已碎
执念已碎 2021-01-26 22:11

Right now I\'m working on a program that takes user input of questions and answers, separates them into separate lists of q\'s and a\'s, then automatically answers the question

1条回答
  •  囚心锁ツ
    2021-01-26 22:22

    The texts e.g. to cloak; to conceal the truth; to offer lame excuses is present in child

    as well in it's parent
    . So extract it you need to induce WebDriverWait for visibility_of_all_elements_located() and you can use either of the following Locator Strategies:

    • Using CSS_SELECTOR and get_attribute():

      print([my_elem.get_attribute("aria-label") for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "div.MatchModeQuestionGridTile-content>div[aria-label]")))])
      
    • Using XPATH and get_attribute():

      print([my_elem.get_attribute("aria-label") for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//div[@class='MatchModeQuestionGridTile-content']/div[@aria-label]")))])
      
    • Note : You have to add the following imports :

      from selenium.webdriver.support.ui import WebDriverWait
      from selenium.webdriver.common.by import By
      from selenium.webdriver.support import expected_conditions as EC
      

    0 讨论(0)
提交回复
热议问题