第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用 Selenium 和 Python 在 https://www.shopdisney

如何使用 Selenium 和 Python 在 https://www.shopdisney

HUX布斯 2023-03-08 10:21:39
我一直在嘗試使用 selenium 和 python 單擊此網(wǎng)頁(yè)上的“創(chuàng)建帳戶”按鈕,但 python 似乎無(wú)法找到該元素。這是我當(dāng)前的代碼:from selenium import webdriverimport timedriver = 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()每次我運(yùn)行它時(shí),chrome 都會(huì)打開(kāi)網(wǎng)頁(yè),但它不會(huì)點(diǎn)擊按鈕,我會(huì)收到以下回復(fù):  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)我已嘗試使用不同的方法來(lái)識(shí)別元素,例如 XPath、css 等,但我仍然無(wú)法找到它并單擊它。我相信它與 Iframe 有關(guān),但我不完全確定。有誰(shuí)知道如何解決這個(gè)問(wèn)題?謝謝!
查看完整描述

1 回答

?
鳳凰求蠱

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊

帶有創(chuàng)建帳戶文本的鏈接位于 中,<iframe>因此您必須:


driver.get("https://www.shopdisney.com/merch-pass/product-selection/arendelle-castle-collection-from-frozen")

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"disneyid-iframe")))

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Create an Account"))).click()

使用CSS_SELECTOR:


driver.get("https://www.shopdisney.com/merch-pass/product-selection/arendelle-castle-collection-from-frozen")

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='disneyid-iframe']")))

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-secondary.ng-isolate-scope"))).click()

使用XPATH:


driver.get("https://www.shopdisney.com/merch-pass/product-selection/arendelle-castle-collection-from-frozen")

WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@name='disneyid-iframe']")))

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='Create an Account']"))).click()

注意:您必須添加以下導(dǎo)入:


from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC

瀏覽器快照:

http://img1.sycdn.imooc.com//6407f1880001d54313620765.jpg

查看完整回答
反對(duì) 回復(fù) 2023-03-08
  • 1 回答
  • 0 關(guān)注
  • 103 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)