19

Iceweasel ブラウザーを使用してラズベリー pi で Selenium を実行しようとするのはこれが初めてです。今夜は簡単なテストをしてみました

# selenium test for /mod2 
# verify: posts, and page name
class TestMod2Selenium(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_validate_page_elements(self):
        driver = self.driver
        driver.get("127.0.0.1:5000/mod2")
        self.assertIn("Home - microblog", driver.title)
    def tearDown(self):
        self.driver.close()

実行時に返されるエラーは次のとおりです。

=====================================================================
ERROR: test_validate_page_elements (__main__.TestMod2Selenium)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test.py", line 58, in setUp
    self.driver = webdriver.Firefox()
  File "/home/pi/naughton_python/flask/flask/local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
    self.binary, timeout),
  File "/home/pi/naughton_python/flask/flask/local/lib/python2.7/site-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
    self.binary.launch_browser(self.profile)
  File "/home/pi/naughton_python/flask/flask/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
    self._wait_until_connectable()
  File "/home/pi/naughton_python/flask/flask/local/lib/python2.7/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
    self._get_firefox_output())
WebDriverException: Message: "The browser appears to have exited before we could connect. The output was: ERROR: ld.so: object 'x_ignore_nofocus.so' from LD_PRELOAD cannot be preloaded: ignored.\nERROR: ld.so: object 'x_ignore_nofocus.so' from LD_PRELOAD cannot be preloaded: ignored.\nERROR: ld.so: object 'x_ignore_nofocus.so' from LD_PRELOAD cannot be preloaded: ignored.\nError: no display specified\n"

私がオンラインで読んだことから理解しているように、Iceweasel は pi で Firefox の代替として機能し、多くの人がそれを使用するには firefox webdriver を呼び出すだけでよいと主張しています。私はこれを間違ってやっていますか?

お時間をいただきありがとうございます。

4

2 に答える 2

38

これは、Raspberry Pi ヘッドレスで機能します。

インストール:

sudo apt-get install python-pip iceweasel xvfb
sudo pip install pyvirtualdisplay selenium

コード:

from selenium import webdriver
from pyvirtualdisplay import Display

display = Display(visible=0, size=(800, 600))
display.start()

driver = webdriver.Firefox()
于 2014-09-08T14:00:35.817 に答える
1

原因はわかりませんが、発生しているエラーは、ユーザー インタラクション シミュレーション (キーボード、マウスなど) に「ネイティブ イベント」を使用する Firefox ドライバーに関係しています。

ネイティブ イベントの技術的な詳細と背景/問題については、 https ://code.google.com/p/selenium/wiki/NativeEventsOnLinux を参照してください。

多くの Selenium ユーザー (私自身を含む) は、「ネイティブ イベント」が多くの状況で問題を抱えていることを発見しており、代わりに「合成イベント」を使用する方が簡単で安全です。合成されたイベントは、JavaScript を介してユーザーの操作をエミュレートします。

そのため、ドライバーで (プロファイル プロパティを設定して) ネイティブ イベントを無効にしてみてください。そうすれば、そのエラーを回避できるはずです。

例:

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.native_events_enabled = False
driver = webdriver.Firefox(profile)
# synthesized events are now enabled for this 
# driver instance... native events are disabled.
于 2014-08-06T18:10:37.740 に答える