Issue
I want to get information from tooltip. I work on flashscore website. And I want to get information about next game. enter image description here
I am unable to map the element of the tooltip.
Could you please help me wxtract this information?
thank you in advance this is my code:
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# Initial Values
webdriver_path = "path_to_webdriver"
url = r"https://www.flashscore.pl/pilka-nozna/hiszpania/laliga"
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service(webdriver_path)
driver = webdriver.Chrome(options=options, service=webdriver_service)
# Open url
driver.get(url)
wait = WebDriverWait(driver, 10)
actions = ActionChains(driver)
element_selector = r"#tournament-table-tabs-and-content > div:nth-child(3) > div:nth-child(1) > div > div > div.ui-table__body > div:nth-child(1) > div.table__cell.table__cell--form > div.tableCellFormIcon.tableCellFormIcon--TBD._trigger_14qf7_41"
tooltip_selector = r"#tournament-table-tabs-and-content > div:nth-child(3) > div:nth-child(1) > div > div > div.ui-table__body > div:nth-child(1) > div.table__cell.table__cell--form > div:nth-child(2) > div"
desired_elem = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, element_selector)))
tooltip_elem = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, tooltip_selector)))
Solution
You need to accept consent (it blocks correct move) and perform move to element via ActionChains
.
After move you need to wait for tooltip to be rendered.
Don't use full selectors.
In your case you can use relative unique selectors by data-testid
attribute.
Buttons that trigger tooltip have unique selector [data-testid*=wcl-badgeForm]
Tooltip has unique selector [data-testid=wcl-tooltip-textLine]`
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
url = r"https://www.flashscore.pl/pilka-nozna/hiszpania/laliga"
options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(options=options)
driver.get(url)
wait = WebDriverWait(driver, 10)
actions = ActionChains(driver)
consent = wait.until(EC.presence_of_element_located((By.ID, 'onetrust-accept-btn-handler')))
consent.click()
wait.until(EC.invisibility_of_element(consent))
results = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, '[data-testid*=wcl-badgeForm]')))
for result in results:
actions.move_to_element(result).perform()
tooltip_elem = wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, '[data-testid=wcl-tooltip-textLine]')))
print(tooltip_elem.text)
Answered By - Yaroslavm
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.