Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何消除selenium中的隐私同意覆盖?_Python_Selenium_Selenium Chromedriver - Fatal编程技术网

Python 如何消除selenium中的隐私同意覆盖?

Python 如何消除selenium中的隐私同意覆盖?,python,selenium,selenium-chromedriver,Python,Selenium,Selenium Chromedriver,这是我的密码: from selenium import webdriver from selenium.webdriver.common.by import By op_path: str = r"D:\Coding\Python\Projekte\Minecraft Updater\stuff\chromedriver.exe" driver=webdriver.Chrome(op_path) driver.get('https://www.curseforge

这是我的密码:

from selenium import webdriver

from selenium.webdriver.common.by import By


op_path: str = r"D:\Coding\Python\Projekte\Minecraft Updater\stuff\chromedriver.exe"

driver=webdriver.Chrome(op_path)

driver.get('https://www.curseforge.com/minecraft/mc-mods')



driver.implicitly_wait(10)

driver.find_element(By.XPATH, '//button[text()="Akeptieren"]').click()
我正试图去刮,但是页面首先要求我同意一些关于cookie隐私的事情。不过,我为“接受”按钮尝试的所有定位器似乎都不起作用。我确保在尝试搜索按钮之前,覆盖层已经弹出,但即使如此,它也会抛出一个“没有这样的元素”错误

下面是accept按钮的HTML部分:

<button tabindex="0" title="Akzeptieren" aria-label="Akzeptieren" class="message-component message-button no-children buttons-row" path="[0,3,1]" style="padding: 10px 18px; margin: 10px; border-width: 1px; border-color: rgb(37, 53, 81); border-radius: 0px; border-style: solid; font-size: 14px; font-weight: 700; color: rgb(37, 53, 81); font-family: arial, helvetica, sans-serif; width: auto; background: rgb(255, 255, 255);">Akzeptieren</button>
Akzeptieren

我不熟悉HTML和selenium,所以我很难理解如何点击这个该死的按钮

您的“接受”按钮位于iframe中

在Selenium中,您需要切换到该框架以访问内容,然后在完成后切换回。 为了允许同步问题,最好使用webdriver等待。关于Selenium的更多信息

这对我有用


driver = webdriver.Chrome() 
driver.get('https://www.curseforge.com/minecraft/mc-mods')

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@id,'sp_message_iframe')]")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Akeptieren']"))).click()
driver.switch_to_default_content()

##continue with your script
selenium文档建议不要混合使用隐式和显式等待。 如果您更愿意坚持隐式方法,这也适用于:

driver = webdriver.Chrome() 
driver.get('https://www.curseforge.com/minecraft/mc-mods')
driver.implicitly_wait(10)

iframe = driver.find_element_by_xpath("//iframe[contains(@id,'sp_message_iframe')]")
driver.switch_to.frame(iframe)
driver.find_element_by_xpath("//button[text()='Akeptieren']").click()
driver.switch_to_default_content()

##continue with your script