ドロップダウンから最初に選択した値を抽出しようとしています。ここでSelenium pythonがドロップダウンから最初に選択したオプション値を抽出しようとしています
currency = Select(self.driver.find_element_by_id("currencyid"))
currency.select_by_visible_text("AUD")
assert currency.first_selected_option().text == "AUD"
は、HTMLコードのように見えるされています:
これは私が誤りである。これは、私がこれまで試してみました何でここで私が間違っている
わかりませんどのように役立つかわからない場合は、
File "Test.py", line 54, in test_TestOne
assert currency.first_selected_option().text == "USD"
File "C:\Python27\lib\site-packages\selenium\webdriver\support\select.py", line 62, in first_selected_option
for opt in self.options:
File "C:\Python27\lib\site-packages\selenium\webdriver\support\select.py", line 47, in options
return self._el.find_elements(By.TAG_NAME, 'option')
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 528, in find_elements
{"using": by, "value": value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 494, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=56.0.2924.87)
(Driver info: chromedriver=2.25.426923(),platform=Windows NT 10.0.10586 x86_64)
'StaleElementReferenceException'は' selenium'があなたの 'element'を見上げたことを意味使用する必要がありますか? )、古い '古い'要素を使用しようとしました。おそらく、ドロップダウンと対話する前に、ページがロードされていることを示す何かを待つことが最善の策でしょう。これをテストするには問題があります。この 'Select(self.driver.find_element_by_id(" currencyid "))'の前に数秒間スリープ状態にしておけば、それが動作するかどうかを調べることができます。 – mrfreester
'selected'オプションを探したいですか? – Beomi
@mrfreester、何が起こっているのか分かりません。私は5秒の睡眠を追加しようとしましたが、5秒間待つことさえありません。このエラーはすぐに – user7242550