使用python selenium脚本加载Firefox,但它将打开skype支持页面

时间:2017-01-10 03:44:48

标签: python selenium firefox

我在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()

1 个答案:

答案 0 :(得分:0)

我不是python / selenium专家,但我认为我遇到了同样的问题。我刚刚在我的Enthought Canopy应用程序中安装了selenium。以下简单代码生成了一个Skype Web浏览器窗口:

#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
"""