# import os
# import time
# from selenium import webdriver
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.support import expected_conditions as EC
# from selenium.webdriver.common.by import By
#
#
# # 指定webdriver的路径
# chrome_driver_path = '/home/avi/.wdm/drivers/chromedriver/linux64/113.0.5672/chromedriver'
#
# # 创建一个Chrome浏览器实例
# driver = webdriver.Chrome(executable_path=chrome_driver_path)
#
# driver.get("https://www.fimea.fi/ajankohtaista/uutiset")
# time.sleep(3)
#
# # 等待iframe出现并获取句柄
# iframe_locator = (By.XPATH, "//iframe[contains(@id,'cf-chl-widget-')]")
# iframe = WebDriverWait(driver, 10).until(EC.presence_of_element_located(iframe_locator))
#
#
#
# # # 定位到iframe
# # iframe = driver.find_element_by_id("cf-chl-widget-p4b2v") # cf-chl-widget-j29dj
# # 切换到iframe
# driver.switch_to.frame(iframe)
#
# # 登录
# # driver.find_element_by_css_selector("input[name='email']").send_keys("xxx")
# # driver.find_element_by_css_selector("input[name='password']").send_keys("xxx")
# # time.sleep(3)
# # driver.find_element_by_id("dologin").click()
#
# # 退出iframe
# driver.switch_to.default_content()
# # 切换到iframe并执行操作
# driver.switch_to.frame(iframe)
# # 在iframe中查找元素并执行操作
# element = driver.find_element_by_xpath("//input[@name='search']")
# element.send_keys("search term")
import time

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

# 指定ChromeDriver路径
chrome_driver_path = "/home/avi/.wdm/drivers/chromedriver/linux64/113.0.5672/chromedriver"

# 创建ChromeDriver实例
driver = webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=chrome_driver_path))

# 打开目标页面
driver.get("https://www.fimea.fi/ajankohtaista/uutiset")

# 等待目标iframe出现
iframe_locator = (By.XPATH, "//iframe[contains(@id,'cf-chl-widget-')]")
iframe = WebDriverWait(driver, 10).until(EC.presence_of_element_located(iframe_locator))

# 切换到目标iframe
driver.switch_to.frame(iframe)
time.sleep(5)
# 等待目标input出现
input_locator = (By.XPATH, "//input[@type='checkbox']")
input_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located(input_locator))
time.sleep(5)
# 点击目标input
input_box.click()
time.sleep(5)

# 切回主页面
driver.switch_to.default_content()


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

# 指定ChromeDriver路径
chrome_driver_path = "/home/avi/.wdm/drivers/chromedriver/linux64/113.0.5672/chromedriver"

# 创建ChromeDriver实例
driver = webdriver.Chrome(service=webdriver.chrome.service.Service(executable_path=chrome_driver_path))

# 打开目标页面
driver.get("https://www.fimea.fi/ajankohtaista/uutiset")

# 等待目标iframe出现
iframe_locator = (By.XPATH, "//iframe[contains(@id,'cf-chl-widget-')]")
iframe = WebDriverWait(driver, 10).until(EC.presence_of_element_located(iframe_locator))

# 切换到目标iframe
driver.switch_to.frame(iframe)

# 等待目标input出现
input_locator = (By.XPATH, "//input[@type='checkbox']")
input_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located(input_locator))

# 点击目标input
input_box.click()

# 切回主页面
driver.switch_to.default_content()