我一直在尝试使用 selenium 和 python 单击此网页上的“创建帐户”按钮,但 python 似乎无法找到该元素。这是我当前的代码:
from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("https://www.shopdisney.com/merch-pass/product-selection/arendelle-castle-collection-from-frozen")
time.sleep(12)
accountcreate = driver.find_element_by_class_name ('btn-group btn-group-create-account ng-scope')
accountcreate.click()
每次我运行它时,chrome 都会打开网页,但它不会点击按钮,我会收到以下回复:
File "skit.py", line 8, in <module>
link = driver.find_element_by_class_name ('btn-group btn-group-create-account ng-scope')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 564, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn-group btn-group-create-account ng-scope"}
(Session info: chrome=83.0.4103.97)
我已尝试使用不同的方法来识别元素,例如 XPath、css 等,但我仍然无法找到它并单击它。我相信它与 Iframe 有关,但我不完全确定。有谁知道如何解决这个问题?
谢谢!
凤凰求蛊
相关分类