0

Here is the sample HTML test.html:

<html>
<div class="h1 mb-4 font-weight-normal nh-read__title"> Test Title </div>
<html>

I tried to get the <div> by selenium:

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

driver = webdriver.Chrome()
driver.get("file://test.html")
element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CLASS_NAME, "h1 mb-4 font-weight-normal nh-read__title"))
)

The page loads instantly, however after 10 seconds, it raises a selenium.common.exceptions.TimeoutException error. I'm not sure what's wrong here since I can get any other element with this code (get by id, ...). I want to get the above <div> by class name only.

The version of chromedriver and python I'm using is 111 and 3.10.

Joey
  • 111
  • 8
  • You can't pass multiple classes in that selector. [See this previous answer](https://stackoverflow.com/a/53536022/21146235) for discussion and possibilities. – motto Apr 01 '23 at 10:22
  • @moto Oh I got it. Thank you so much!. Can you post this comment as an answer so I can mark the question as solved? – Joey Apr 01 '23 at 10:32
  • 2
    Glad it helped! Prefer not to duplicate existing answers so you get this one for free :-) – motto Apr 01 '23 at 10:33

0 Answers0