【发布时间】:2016-10-16 17:19:03
【问题描述】:
所以我编写了一个使用 Selenium 2 对我的调制解调器执行各种操作的 python 脚本。这完全有效。
我现在正忙于更新脚本以使用 Selenium 3,但我立即遇到了一个问题,我什至无法进入调制解调器的登录页面。问题似乎出在get()。
首先,它现在在给定虚假 URL 时会崩溃。然后我给了它谷歌 URL,它运行良好,但现在我需要转到调制解调器的 IP。但是当我使用driver.get(_rout_ip)(其中_rout_ip 是10.0.0.2)时,它只是将IP 地址附加到Google URL。删除虚假 URL 的 get 不是一种选择,因为由于某种原因,它是必需的,因为它不能直接转到调制解调器 ip。
获取webdriver实例的代码如下
def get_driver():
"""
Get an instance of a webdriver that is initialized to the router login page
:return: A webdriver instance
"""
if not os.path.exists(os.getcwd() + '\\' + _driver_name):
print('ERROR: The specified driver does not exist, %s' % (os.getcwd() + '\\' + _driver_name))
exit()
print "Initializing the webdriver"
# Set the path to the driver to be used
os.environ["webdriver.gecko.driver"] = os.getcwd() + '\\' + _driver_name
driver = webdriver.Firefox()
# Go to a fake website. This is needed since it cannot go to the modem directly for some reason
try:
driver.get('http://poop_smells_nice.com')
except Exception:
print('WOOT')
waiter.sleep(_SLEEP_TIME) # Pause a bit to be safe
print "Switching to the router login page"
# Go to the modem ip
driver.get(_rout_ip)
driver.switch_to.default_content()
return driver
有人知道为什么会这样吗?
【问题讨论】:
标签: python selenium firefox selenium-webdriver