首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium GDPR NoSuchElementException

Selenium GDPR NoSuchElementException
EN

Stack Overflow用户
提问于 2020-08-14 05:40:31
回答 2查看 157关注 0票数 1

我想从https://www.techadvisor.co.uk/review/wearable-tech/"中抓取一些数据。我发现用Beautifulsoup在页面中循环是行不通的。这就是为什么我尝试用selenium打开它的原因。

我试过了:

代码语言:javascript
复制
browser = webdriver.Chrome()
browser.get("https://www.techadvisor.co.uk/review/wearable-tech/")
# button = browser.find_element_by_xpath('/html/body/div/div[3]/div[5]/button[2]')
# WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "html/body/div/div[3]/div[5]/button[2]"))).click()

我总是收到NoSuchElementException

老实说,我发现Xpath真的很奇怪,但这是我从Google Chrome检查中得到的。

感谢每个解决方案建议或技巧:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-14 06:27:47

要单击iframe.You中的Accept All按钮,需要先切换到iframe才能单击该按钮。

归纳WebDriverWait()并等待frame_to_be_available_and_switch_to_it(),然后使用下面的css选择器。

归纳WebDriverWait()并等待element_to_be_clickable(),然后使用下面的xpath选择器。

代码语言:javascript
复制
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

browser = webdriver.Chrome()
browser.get("https://www.techadvisor.co.uk/review/wearable-tech/")
WebDriverWait(browser,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[id^='sp_message_iframe']")))
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Accept All']"))).click()
票数 0
EN

Stack Overflow用户

发布于 2020-11-03 02:51:41

我知道这个问题很老,但我想提供我自己的解决方案!第一步是识别你实际查看的表单的"id“,然后你需要将焦点移到它上面!

代码语言:javascript
复制
driver.switch_to_frame(driver.find_element_by_xpath('//*[@id="gdpr-consent-notice"]'))

    cookies = driver.find_element_by_xpath('/html/body/app-root/app-theme/div/div/app-notice/app-theme/div/div/app-home/div/div[3]/div[2]/a[3]/span')

    cookies.click()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63403604

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档