Snehasisbasu
Snehasisbasu

Reputation: 69

Selenium Not Able to Find Elements By ClassName

<table class="sc-fAEnHe ePMtc">
<tbody>
<tr class="sc-fAEnHe ePMtc">
<td classs"sc-jEECVv IBUtl">
</td>
</tr>

When I use Selenium's Find element by class it is able to find the element, I even tried replacing space (after e and r or v and I) with ".", "-" and "_" but it did not worked. I Used The Code Below

try:
    match_history_table = WebDriverWait(driver, 30).until(
        EC.presence_of_element_located((By.CLASS_NAME, 'sc-fAEnHe ePMtc'))
    )
except Exception:
    print("Error Finding Match History Table")
    driver.quit()

It always returned the Exception (EC is selenium.webdriver.support.expected_conditions) >Note: Find Elements By Tag is not an Option For me

Upvotes: 3

Views: 2483

Answers (2)

Itay Levy
Itay Levy

Reputation: 91

  1. when you search for class name value, notice that "sc-fAEnHe ePMtc" represent 2 class names separated by space, so you can search by "sc-fAEnHe" or by "ePMtc"
  2. besides that make sure that presence_of_element_located doesn't require an element with height and width that greater then 0

Upvotes: 1

Max Daroshchanka
Max Daroshchanka

Reputation: 2968

This is doc from By.CLASS_NAME found in selenium-java-bindings.

Find elements based on the value of the "class" attribute. Only one class name should be used. If an element has multiple classes, please use cssSelector(String).

Try with (By.CSS_SELECTOR, '.sc-fAEnHe.ePMtc'):

try:
    match_history_table = WebDriverWait(driver, 30).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, '.sc-fAEnHe.ePMtc'))
    )
except Exception:
    print("Error Finding Match History Table")
    driver.quit()


Referenses

class name Returns an element whose class name contains the search value; compound class names are not permitted.

Upvotes: 2

Related Questions