【发布时间】:2020-10-14 01:07:45
【问题描述】:
在学习 python 自动化时尝试自动化 YouTube 搜索,但是我遇到了一个问题。我不知道如何自动点击弹出窗口上的“我同意”,希望有人可以发送解决方案
【问题讨论】:
-
//span[text()='我同意'] 如果你可以在开发者工具上找到这个标签,只需点击 /parent:button 标签。
标签: python selenium automation
在学习 python 自动化时尝试自动化 YouTube 搜索,但是我遇到了一个问题。我不知道如何自动点击弹出窗口上的“我同意”,希望有人可以发送解决方案
【问题讨论】:
标签: python selenium automation
您可以使用 xpath 找到该元素并使用 click() 方法单击它:https://pythonspot.com/selenium-click-button/
【讨论】:
切换到 iframe 弹出窗口
driver.switch_to.frame("iframe") //(对于这个特定的例子,"iframe",否则把 iframe 的 id 放在那里)
driver.find_element_by_xpath('//*[@id="introAgreeButton"]/span/span').click()
切换回主框架
driver.switch_to.default_content()
【讨论】:
browser.switch_to_default_content()
browser.switch_to.frame(browser.find_elements_by_tag_name('iframe')[0])
browser.implicitly_wait(1)
browser.find_element_by_id('introAgreeButton').click()
browser.switch_to.default_content()
我在这里使用“浏览器”而不是“驱动程序”。
【讨论】: