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
2 Answers
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)
5 Comments
dillion n
gyazo.com/110682163d9048bd64c1f8fb346a447d Im getting this error
dillion n
not working unfortunately, I dont understand keeps giving me no element exception when it should work
Ro0t
if you pass me the link of the site I can find the problem faster
dillion n
The link of the site is edgenuity, which is for online school work so i dont believe youll be able to access it
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
1 Comment
dillion n
No it is not working getting this error [code]Traceback (most recent call last): File "<pyshell#47>", line 1, in <module> element = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='Practice_Question_Body'][contains(.,'What is the purpose of'"))) File "C:\Users\Dillionb\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: [/code]
