I'm starting to learn 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
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")
Here is a pic of the source code im trying to find using find_element. What am I doing wrong? Thanks in advance!
CodePudding user response:
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
CodePudding user response:
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']")