get_attributeで属性を取得するとき、なぜか下記のエラーが出る時があります。
8行目でエラーが出ています。
8行目がnoneと出力される時があるので、存在しないときにエラーが出ている訳ではないかもしれません。
Python
1main = driver.find_elements(By.TAG_NAME, "main") 2sleep(10) 3divs = main[0].find_elements(By.TAG_NAME, "div") 4for i, sent in enumerate(divs): 5 sleep(0.1) 6 print(i) 7 print(sent) 8 print(sent.get_attribute("data-testid"))
zsh
1Message: The element reference of <div class="xxx yyy"> is stale; either the element is no longer attached to the DOM, it is not in the current frame context, or the document has been refreshed
下記リンクのページに下記のコードがありましたが、for link の部分が理解できませんでした。
下記のように記載することで問題が解決できる可能性はありますでしょうか?
ご存知の方おられましたら、ご教示お願いいたします。
Python
1links_hrefs = [link.get_attribute('href') for link in links]

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/04/07 06:34