from bs4 import BeautifulSoup as soup
from openpyxl import load_workbook
from openpyxl.styles import PatternFill, Font
from selenium import webdriver
from selenium.webdriver.common.by import By
import datetime
import os
import time
import re
browser = webdriver.Chrome(executable_path=r"C:\Program Files(x86)\Google\Chrome\Application\chromedriver.exe")
my_url = 'https://www.eex.com/en/market-data/power/futures/phelix-at-futures#!/2017/07/24'
browser.get(my_url)
button = browser.find_elements_by_class_name('ng-scope')[-1]
browser.execute_script("arguments[0].click();", button)
它没有给我任何错误,但实际上并没有点击。它应该逐月变化,因为它是最后一个元素,但它保留在那里。
最佳答案
根据您提供的url,单击文本为年份的元素,您必须为引发WebDriverWait可点击的元素如下:
CSS_SELECTOR
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "ul.tabs.filter_wrap.clearfix li.ng-scope:nth-child(3)>a"))).click()
XPATH
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//ul[@class='tabs filter_wrap clearfix']//li[@class='ng-scope']/a[contains(.,'Year')]"))).click()
关于Python- Selenium : How to click on the element with text as "Year" within the webpage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51149507/