3

I'm learning how to use Selenium. I was doing some testing, but got this error:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .layout layout-base

My Code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.common.by import By

driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
driver.get("https://page.onstove.com/epicseven/global/list/e7en003?listType=2&direction=latest&page=1")
driver.find_element(By.CLASS_NAME,"layout layout-base")

Image of: The source code I'm trying to find using find_element.

What am I doing wrong?

1
  • maybe try using a sleep to give the site time to load all the elements into the DOM Commented Dec 27, 2021 at 22:18

2 Answers 2

1

layout layout-base are two class name values separated by a space.
To locate this element you can use any of the following ways:

driver.find_element(By.CLASS_NAME,"layout.layout-base")

Or

driver.find_element(By.CSS_SELECTOR,"div.layout.layout-base")

Or

driver.find_element(By.XPATH,"//div[@class='layout layout-base']")
Sign up to request clarification or add additional context in comments.

Comments

1

You can't pass multiple classnames as argument through find_element(By.CLASS_NAME,"classname") and doing so you will face an error as:

invalid selector: Compound class names not permitted

Solution

As an alternative you can use either of the following Locator Strategies:

  • Using CLASS_NAME layout:

    driver.find_element(By.CLASS_NAME, "layout")
    
  • Using CLASS_NAME layout:

    driver.find_element(By.CLASS_NAME, "layout-base")
    
  • Using CSS_SELECTOR:

    driver.find_element(By.CSS_SELECTOR, ".layout.layout-base")
    
  • Using XPATH:

    driver.find_element(By.XPATH, "//*[@class='layout layout-base']")
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.