如何使用Selenium在Pycharm中打开Goog​​le的移动版本?

时间:2019-07-26 17:20:38

标签: python selenium google-chrome mobile pycharm

我得到了一些代码,可以查看Instagram的移动版本,但是每当我尝试将代码放入类并运行该类时,它都会失败。我有一个用于编写方法的类,以及另一个用于调用方法的类。当我运行第二堂课时,chromedriver将打开chrome,但不会调用instagram URL。

这是有效的代码

from selenium import webdriver

mobile_emulation = { "deviceName": "iPhone X" }
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", 
mobile_emulation)
driver = webdriver.Chrome(executable_path='/Users/~~/chromedriver', chrome_options=chrome_options)
driver.get("https://instagram.com/")

我试图制作一个类来保存这样的代码

from selenium import webdriver

mobile_emulation = {"deviceName": "iPhone X"}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", 
mobile_emulation)
driver = webdriver.Chrome(executable_path='/Users/~~/chromedriver',
                      chrome_options=chrome_options)
class IGFrame:
    def __init__(self, driver):
        self.driver = driver

    def open_ig(self):
        self.driver.get("https://instagram.com/")
        time.sleep(2)

然后这是调用方法的类

from version1.pages.basic_methods import *

class TestSetUp:

    def __init__(self, driver):
        self.driver = driver

    def test_mobileViewOfIG(self):
        methods = IGFrame(self.driver)
        methods.open_ig()

我的目标是在IGFrame类中具有驱动程序设置和调用URL的方法,然后从TestSetUp类中调用该方法。我在做什么错,应该怎么办?

0 个答案:

没有答案