简体   繁体   中英

Selenium python trouble finding element

在此处输入图像描述

Im trying to access the highlighted image but am having trouble I have tried the XPATH and CSS SELECTOR but neither seem to be working. Using Selenium w python & chrome btw

from selenium import webdriver
import os
cwd = os.getcwd()
driver = webdriver.Chrome(cwd+'/chromedriver')
driver.get('site_url')     
all_spans=driver.find_elements_by_xpath("//span[@class='Practice_Question_Body']")
for span in all_spans:
    textHtml =span.get_attribute('innerHTML')

cwd is your directory(obviously i don't know where chromedriver is)

Try below xpath:

wait = WebDriverWait(driver, 10)
element =wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='Practice_Question_Body'][contains(.,'What is the purpose of')]")))

Note: please add below imports to your solution

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM