webdriver.get(url)不能是Selenium 3中的IP地址

时间:2016-10-16 17:19:03

标签: python selenium firefox selenium-webdriver

所以我编写了一个python脚本,它使用Selenium 2为我的调制解调器做各种事情。这完全有效。

我现在正在忙着更新脚本以使用Selenium 3,但我立刻遇到了一个问题,我甚至无法进入调制解调器的登录页面。问题似乎与get()

有关

首先,当给出假URL时它会崩溃。我然后给它了谷歌URL,它完美地工作,但现在我需要去调制解调器的IP。但是当我使用driver.get(_rout_ip)_rout_ip 10.0.0.2 时,它只会将IP地址附加到Google网址。删除虚假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

有谁知道为什么会这样?

1 个答案:

答案 0 :(得分:1)

10.0.0.2不是网址,因此浏览器会重新搜索它。试试http://10.0.0.2/