我想遍歷href鏈接並點擊每個鏈接。我的問題是我無法提取href,因爲它不能幫助我,當我點擊它時,我得到一個空白頁面。我應該直接點擊按鈕列表。迭代點擊href鏈接列表
共有21個節點,hrefList包含21個項目。
這裏是例子的html:
<div class="inner25">
<a href="https://www.ida.org.il/?categoryId=96318&itemId=236252">כרטיס רופא ></a>
</div>
<div class="inner25">
<a href="https://www.ida.org.il/?categoryId=96318&itemId=238647">כרטיס רופא ></a>
</div>
我的代碼是:
hrefList = driver.find_elements_by_xpath(".//a[contains(text(), 'כרטיס רופא')]")
for link in hrefList:
link.click()
在每次看病廣場。我想點擊它們中的每一個。
我發現該循環打開第一個鏈接,然後失敗。什麼可能是一個問題?
I tried also this code:
for href in range(1,3):
hrefList[href].click()
First link it open, and then failed.
This is an error :
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 78, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 499, in _execute
return self._parent.execute(command, params)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 297, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=60.0.3112.113)
(Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.15063 x86_64)
如果您可以分享英文和文字的頁面細節,您要點擊,拍攝屏幕截圖並將其置於有問題 – thebadguy
您的xpath(「.// a [contains(text(),'你已經共享了 – thebadguy
你的xpath不正確 – iamsankalp89