seleniumでchromeにアクセスし、スマホ版を表示させるテストをおこなっています。
にある
Python
1from selenium import webdriver 2mobile_emulation = { "deviceName": "Nexus 5" } 3chrome_options = webdriver.ChromeOptions() 4chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) 5driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', 6 desired_capabilities = chrome_options.to_capabilities())
の「http://127.0.0.1:4444/wd/hub」のところをアクセス先である「http://nicovideo.jp/」に変更して使ってみたのですが
python
1driver = webdriver.Remote(command_executor='http://nicovideo.jp/', 2 desired_capabilities = chrome_options.to_capabilities())
のところで 「Exception has occurred: TypeError
string indices must be integers」と出てきてしまいます。
もともと引数に整数値は入らないと思うのですが、どなたか分かる方いらっしゃいますか?
サンプルにある「http://127.0.0.1:4444/wd/hub」というURLはアクセス先に変えてもいいのでしょうか。
追記 : ご指摘ありがとうございます。
コマンドプロンプトにでたエラーです
python
1DevTools listening on ws://127.0.0.1:54013/devtools/browser/255648f5-1d00-46c4-bcf2-851ad6ba1d0d 2Traceback (most recent call last): 3 File "C:\python\brow.py", line 15, in <module> 4 driver = webdriver.Remote(command_executor='http://nicovideo.jp/',desired_capabilities = chrome_options.to_capabilities()) 5 File "C:\Users****\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__ 6 self.start_session(capabilities, browser_profile) 7 File "C:\Users****\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py", line 254, in start_session 8 self.session_id = response['sessionId'] 9TypeError: string indices must be integers
回答2件
あなたの回答
tips
プレビュー