When the code below is run it raises this exception: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {“method”:”css selector”,”selector”:”.match-on no-top-border “}
<code>from selenium.webdriver.common.by import By
def Main():
driver = webdriver.Chrome()
url = "https://www.oddschecker.com/tennis"
driver.get(url)
driver.implicitly_wait(2)
link = driver.find_element(By.CLASS_NAME, "match-on no-top-border ")
print(link.text)```
The code is attempting to find the following element: <tr data-mid="3566792067" class="match-on no-top-border " data-ng-class="{ 'hide-row' : MainController.mainNav.hideCouponRows['2024-07-2738851513'] }" data-day="Today"></tr>.
The error only occurs when using the CLASS_NAME locator, the code runs fine when using CSS_SELECTOR, however it needs to run with CLASS_NAME to select all instances of the class when run with find_elements.
</code>
<code>from selenium.webdriver.common.by import By
def Main():
driver = webdriver.Chrome()
url = "https://www.oddschecker.com/tennis"
driver.get(url)
driver.implicitly_wait(2)
link = driver.find_element(By.CLASS_NAME, "match-on no-top-border ")
print(link.text)```
The code is attempting to find the following element: <tr data-mid="3566792067" class="match-on no-top-border " data-ng-class="{ 'hide-row' : MainController.mainNav.hideCouponRows['2024-07-2738851513'] }" data-day="Today"></tr>.
The error only occurs when using the CLASS_NAME locator, the code runs fine when using CSS_SELECTOR, however it needs to run with CLASS_NAME to select all instances of the class when run with find_elements.
</code>
from selenium.webdriver.common.by import By
def Main():
driver = webdriver.Chrome()
url = "https://www.oddschecker.com/tennis"
driver.get(url)
driver.implicitly_wait(2)
link = driver.find_element(By.CLASS_NAME, "match-on no-top-border ")
print(link.text)```
The code is attempting to find the following element: <tr data-mid="3566792067" class="match-on no-top-border " data-ng-class="{ 'hide-row' : MainController.mainNav.hideCouponRows['2024-07-2738851513'] }" data-day="Today"></tr>.
The error only occurs when using the CLASS_NAME locator, the code runs fine when using CSS_SELECTOR, however it needs to run with CLASS_NAME to select all instances of the class when run with find_elements.
New contributor
Dan Low is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.