Japo Japic
Japo Japic

Reputation: 77

Find element with compound class in Selenium

I can see some posts about this topic but unfortunately, none worked in my case. I am trying to locate elements with compounded classes in its name. This is the name of the elements class:

class="group-header__wrapper is-grid-view-active section--prematch markets-optimized--3"

I tried with this line of code, which is not working:

containers = SBdriver.find_elements(By.CSS_SELECTOR,".group-header.wrapper.is-grid-view-active.section.prematch.markets-optimized--3")

Am I right to assume the class consists of 3 other classes or there are more? This is my entire code so far:

from datetime import datetime
from lib2to3.pgen2 import driver
from os import pardir
import time
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from urllib.parse import urlparse, parse_qs
import re
import pandas as pd
import numpy as np
from selenium.webdriver.remote.webelement import BaseWebElement
from googletrans import Translator
import time
import schedule

SB_datalist = []

SBdriver = webdriver.Chrome('C:/Users/tmarkac/source/repos/chromedriver.exe')
superbet_ufootball_url= 'https://superbet.pl/zaklady-bukmacherskie/pilka-nozna'
SBdriver.get(superbet_ufootball_url)
SBdriver.find_element(By.XPATH,'//*[@id="onetrust-accept-btn-handler"]').click()
containers = SBdriver.find_elements(By.CSS_SELECTOR,".group-header__wrapper.is-grid-view-active.section--prematch.markets-optimized--3")
SB_datalist.append(containers)
print("Cont: ",SB_datalist)

Upvotes: 0

Views: 147

Answers (1)

Lewis Morris
Lewis Morris

Reputation: 2134

EDIT:

Tested your code and you can select the elements you want with this...

SBdriver.find_elements(By.CSS_SELECTOR, ".group-header__wrapper.section--prematch.markets-optimized--3")


you need it constructed like this

.group-header__wrapper.is-grid-view-active.section--prematch.markets-optimized--3

you have a . where the __ is but that is incorrect that is one class name

group-header__wrapper

Upvotes: 1

Related Questions