0

私は自分のプロジェクトにセレンを使用する必要があります.セレンを使用しているときは、このように各ステップで

   time.sleep(6)

特定のページをロードするのに十分な間隔を与えていますが、それでもある時点で以下のエラーに直面しています。ほとんどの場合、次のような例外が発生します

通常の例外:

   Exception: Message: u'Unable to locate element:   {"method":"xpath","selector":"//textarea[@style=\\"overflow-y: hidden; height: 50px; width:  300px;\\"]"}' ; Stacktrace: Method WebDriverError threw an error in    file:///tmp/tmpBxGp2P/extensions/fxdriver@googlecode.com/resource/modules/atoms.js 
   Traceback (most recent call last):
    File "crawl_optimize.py", line 206, in main
     word_query = browser.find_element_by_xpath('//textarea[@style="overflow-y: hidden; height: 50px; width: 300px;"]')
    File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 210, in find_element_by_xpath
     return self.find_element(by=By.XPATH, value=xpath)
    File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 643, in find_element
    {'using': by, 'value': value})['value']
   File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 153, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/remote/errorhandler.py", l     ine 147, in check_response
     raise exception_class(message, screen, stacktrace)

また、WebDriverWait().Until() が原因で No such Implementation Error が発生します。

    NoSuchElementException: Message: u'Unable to locate element: {  "method":"xpath","selector":"//textarea[@style=\\"overflow-y: hidden; height: 50px; width: 300px;\\"]"}' ; Stacktrace: Method WebDriverError threw an error in   file:///tmp/tmpBxGp2P/extensions/fxdriver@googlecode.com/resource/modules/atoms.js 
  keyword : balance transfer ad pos : 2
  Exception: Message: None 
  Traceback (most recent call last):
    File "crawl_optimize.py", line 228, in main
     start_cpc,end_cpc = set_initial_cpc(initial_max_cpc,ad_position)
    File "crawl_optimize.py", line 95, in set_initial_cpc
    ep = crawl_position(cost)
   File "crawl_optimize.py", line 82, in crawl_position
    WebDriverWait(browser, 10).until(lambda driver :   driver.find_element_by_link_text(word.lower()))
   File "/usr/local/lib/python2.6/dist-packages/selenium/webdriver/support/wait.py", line 55, in until
    raise TimeoutException()
    TimeoutException: Message: None 

そのような例外を取り除く方法は何ですか?

4

1 に答える 1

0

2つのことかもしれません。

  1. 割り当てられた 6 秒以内に要素の読み込みが完了していません
  2. ロケーターの形式が正しくありません。これは疑わしいようです...

    { "メソッド":"xpath","セレクター":"//textarea[@style=\"overflow-y: hidden; 高さ: 50px; 幅: 300px;\"]"}'

FireFinder などを使用して、ロケーターが期待どおりの結果を返すことを確認できますか?

ロケーターに問題がない場合は、WebDriverWait と ExpectedCondition を使用して、ページが常に 6 秒で読み込まれるというギャンブルではなく、ページの読み込みが完了したことを確認できます。

于 2012-02-03T06:36:12.050 に答える