我正在查看此頁(yè)面,需要免費(fèi)注冊(cè)才能登錄。在此頁(yè)面中,我嘗試選擇“#histo-line-chart > g > g.hist-container > g.hist-top-graph > g.hist-spreadlines > g”。def login(): url = "https://www.datagrapple.com/Account/Login" browser = create_browser( r'C:/Users/YOURADDRESS/webdrivers/chromedriver.exe') # change addr when necessary browser.get(url) browser.find_element_by_id('UserName').send_keys('EXIA2018') # valid demo browser.find_element_by_id('Password').send_keys('102938') browser.find_element_by_xpath('//*[@id="loginForm"]/form/fieldset/div[3]/div/button').click() return browserobj_path = '#histo-line-chart > g > g.hist-container > g.hist-top-graph > g.hist-spreadlines > g'WebDriverWait(browser, 60).until(EC.element_to_be_clickable((By.CSS_SELECTOR, obj_path))) # added according to NatalSnowyFox's suggestion. browser.find_element_by_css_selector(obj_path)然后我得到了這個(gè)錯(cuò)誤。selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"histo-line-chart > g > g.hist-container > g.hist-top-graph > g.hist-spreadlines > g"} (Session info: headless chrome=79.0.3945.130)當(dāng)我以檢查模式將此 css 選擇器粘貼到瀏覽器時(shí),它可以成功找到目標(biāo)。我正在使用 Python 3.7.6 和 selenium 3.141.0。我已經(jīng)重新安裝了硒以防萬(wàn)一。請(qǐng)指導(dǎo)我完成,謝謝你。更新 1根據(jù) NatalSnowyFox 的建議添加了顯式等待代碼,但即使我將超時(shí)時(shí)間延長(zhǎng)到 60 秒也會(huì)出現(xiàn)超時(shí)錯(cuò)誤
selenium css 選擇器無(wú)法獲取目標(biāo),而目標(biāo)在檢查模式下可見且可選擇
尚方寶劍之說(shuō)
2022-07-19 15:30:43