dillion n
dillion n

Reputation: 69

Selenium python trouble finding element

enter image description here

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

Upvotes: 0

Views: 91

Answers (2)

Ro0t
Ro0t

Reputation: 179

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)

Upvotes: 2

SeleniumUser
SeleniumUser

Reputation: 4177

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

Upvotes: 1

Related Questions