简体   繁体   English

单击具有 selenium 的元素

[英]Click an element with selenium

I'm trying to scrape this page:我正在尝试抓取此页面:

https://www.ultimatetennisstatistics.com/tournamentEvent?tournamentEventId=4073 https://www.ultimatetennisstatistics.com/tournamentEvent?tournamentEventId=4073

And I want to click in every blue stats icon (there is one for every match of the tournament)我想点击每个蓝色统计图标(锦标赛的每场比赛都有一个)

This is my code:这是我的代码:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


path="C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(path)

URL = "https://www.ultimatetennisstatistics.com/tournamentEvent?tournamentEventId=4073"
driver.get(URL)

driver.implicitly_wait(10)
cookies = driver.find_element_by_id("cookiesNotification")
cookies.click()
# Trying to click the cookies

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "matchStats-171140")))
element.click()

This is the answer that I get:这是我得到的答案:

ElementClickInterceptedException: element click intercepted: Element <a...id="matchStats-171140" href="#" class="btn btn-info btn-xxs glyphicon glyphicon-stats" onclick="showMatchStats(171140, event, false)" title="Match Statistics"> </a> is not clickable at point (880, 566). Other element would receive the click: <div id="cookiesNotification" style="position: fixed; left: 0px; bottom: 0px; width: 100%; z-index: 100; text-align: center; background-color: indigo; color: wheat; opacity: 0.9; padding: 10px;">...</div>

I tried clicking the cookies's button but it didn't work...我尝试点击 cookie 的按钮,但没有成功...

The output I want, eg by clicking on the finals, should look like this我想要的 output,例如点击决赛,应该是这样

Can anyone help me?谁能帮我?

Thank you谢谢

You can use javascript executor to click on Accept cookies button:-您可以使用 javascript 执行器单击接受 cookies 按钮:-

WebElement acceptCookieButton = driver.findElement(By.linkText("OK, I agree"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", acceptCookieButton);

Once, cookie is accepted, all your web elements will be clickable.一旦接受 cookie,您的所有 web 元素都将是可点击的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM