【问题标题】:Load Firefox with python selenium script, but it will open the skype support page使用 python selenium 脚本加载 Firefox,但它会打开 Skype 支持页面
【发布时间】:2017-01-10 03:44:47
【问题描述】:

我在 Firefox 中通过 selenium IDE 录制了一个脚本,并导出到 python webdriver。但是当我运行代码时,它会同时打开Skype支持页面。不知道为什么。

我的firefox是最新的(50.1.0),python 2.7.12,selenium 3.0.2

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class Test2(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://www.cic.gc.ca/english/visit/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_2(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.find_element_by_id("kw").click()
        driver.find_element_by_id("kw").clear()
        driver.find_element_by_id("kw").send_keys("tt")
        driver.find_element_by_id("su").click()

    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True

    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True

    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True

    # def tearDown(self):
    #     self.driver.quit()
    #     self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

【问题讨论】:

  • 在工具 > 选项 > 常规 ....主页上检查 Firefox 的默认页面,因为您的脚本看起来不错

标签: python selenium firefox


【解决方案1】:

我不是 python/selenium 专家,但我想我遇到过同样的问题。我最近在我的 Enthought Canopy 应用程序中安装了 selenium。下面的简单代码会生成一个 Skype 网络浏览器窗口:

#file: selenium2.py . 
from selenium import webdriver
#browser = webdriver.Chrome()
browser = webdriver.Firefox()
browser.get('http://seleniumhq.org/') # always gets skype ???
"""
This url window is the response:
https://support.skype.com/en/faq/FA34612/what-is-the-skype-extension
"""

【讨论】:

    猜你喜欢
    • 2016-09-10
    • 2020-08-02
    • 2017-03-04
    • 1970-01-01
    • 2019-05-10
    • 1970-01-01
    • 1970-01-01
    • 2016-09-22
    • 1970-01-01
    相关资源
    最近更新 更多