gpt4 book ai didi

python - 如何使用 Selenium 自动化网页按钮控制?

转载 作者:行者123 更新时间:2023-12-01 04:50:43 25 4
gpt4 key购买 nike

如何使用 span 子项自动执行网页按钮控制

驱动程序。 findElement_by_xpath()

Ubuntu Linux 和 chromium 自动测试

网站是:https://www.youtube.com/my_webcam?privacy=public

我想单击“开始录制”按钮。HTML 来源是:

<button class="yt-uix-button yt-uix-button-size-default yt-uix-button-dark yt-uix-button-has-icon webcam-record-button" type="button" onclick=";return false;" id="record-button">
<span class="yt-uix-button-icon-wrapper">
<span class="yt-uix-button-icon yt-uix-button-icon-upload yt-sprite">
</span>
</span>
<span class="yt-uix-button-content">Start recording </span>
</button>

我们已经尝试过使用

driver.find_element_by_css_selector() 
driver.find_element_by_id()
driver.find_element_by_xpath ()

但是,没有任何效果。您能给我们建议适当的解决方案吗?

最佳答案

录制按钮位于 iframe 内,您需要先切换该 iframe,然后使用您选择的选择器找到该按钮。

iframe = self.driver.find_element_by_css_selector("#webcam-container")
self.driver.switch_to_frame(iframe)
record = self.driver.find_element_by_css_selector("#record-button > span.yt-uix-button-content")
record.click()

关于python - 如何使用 Selenium 自动化网页按钮控制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28566184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com