gpt4 book ai didi

python - Spotify 网络播放器 : Select Element 'Play' Button w/Selenium

转载 作者:太空宇宙 更新时间:2023-11-04 03:27:06 25 4
gpt4 key购买 nike

我一直试图通过 selenium 在 Spotify 的网络播放器上选择 Play 按钮进行一系列测试,但一直无法成功定位它。我已经尝试通过 CSS 选择器:

driver.find_element_by_css_selector("#header .button-primary").click()

xpath:

driver.find_element_by_xpath("//button[@class=\"button-primary\"]")

这是我的错误调用堆栈:

Traceback (most recent call last): File "Spotify Dumbass.py", line 37, in test_spotify_dumbass driver.find_element_by_css_selector("#header .button-primary").click() File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 396, in find_element_by_css_selector return self.find_element(by=By.CSS_SELECTOR, value=css_selector) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 684, in find_element {'using': by, 'value': value})['value'] File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 195, in execute self.error_handler.check_response(response) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 170, in check_response raise exception_class(message, screen, stacktrace) NoSuchElementException: Message: Unable to locate element: {"method":"css selector","selector":"#header .button-primary"} Stacktrace: at FirefoxDriver.prototype.findElementInternal_ (file:///var/folders/Ne/NepmGbBUFwK7TxfPj5g0gE+++TI/-Tmp-/tmpSLKAhJ/extensions/fxdriver@googlecode.com/components/driver-component.js:10299) at fxdriver.Timer.prototype.setTimeout/<.notify (file:///var/folders/Ne/NepmGbBUFwK7TxfPj5g0gE+++TI/-Tmp-/tmpSLKAhJ/extensions/fxdriver@googlecode.com/components/driver-component.js:603)

最佳答案

“播放”按钮在 iframe 中,在定位元素之前切换到它:

driver.switch_to.frame("app-player")
play = driver.find_element_by_id("play-pause")
play.click()

关于python - Spotify 网络播放器 : Select Element 'Play' Button w/Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32620164/

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