在Selenium IED里面导出的.py文件在pycharm运行浏览器调取不了
# -*- coding: utf-8 -*-
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver #导入驱动,
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
time.sleep(5)

class TestDenglu():
  def setup_method(self, method):
    self.driver = webdriver.Chrome()
    self.vars = {}

  def teardown_method(self, method):
    self.driver.quit()

  time.sleep(5)

  def test_denglu(self):
    # Test name: denglu
    # Step # | name | target | value | comment
    # 1 | open | / |  |
    self.driver.get("http://192.168.1.118:8083/")
    # 2 | setWindowSize | 945x1140 |  |
    self.driver.set_window_size(945, 1140)
    time.sleep(5)

    # 3 | click | css=.login |  |
    self.driver.find_element(By.CSS_SELECTOR, ".login").click()
    # 4 | click | css=.login-input:nth-child(3) > input |  |
    self.driver.find_element(By.CSS_SELECTOR, ".login-input:nth-child(3) > input").click()
    # 5 | click | css=.login |  |
    self.driver.find_element(By.CSS_SELECTOR, ".login").click()
    # 6 | click | css=.login-input:nth-child(3) > input |  |
    self.driver.find_element(By.CSS_SELECTOR, ".login-input:nth-child(3) > input").click()
    # 7 | click | css=.login-button |  |
    self.driver.find_element(By.CSS_SELECTOR, ".login-button").click()


```![图片说明](https://img-ask.csdn.net/upload/201909/27/1569567359_21132.png)


在Selenium IED里面导出的.py文件在pycharm运行浏览器调取不了

2个回答

我一开始用selenium录制,将py文件导入到pycharm也没法运行,会报错ModuleNotFoundError: No module named 'pytest',
后面安装了pytest(命令行运行pip install -U pytest)(这个网上多的是,随便搜一搜就有)
然后需要在导入的程序最后面加一个main函数,如下两行:
if name == '__main__':
pytest.main()
然后就可以运行啦!
录屏的话,要注意有些寻找标签的地方需要让测试网址加载一段时间,以上还不能运行的话,就在报错的那一行上面加一个sleep(x),x填等待时长,让它找一会儿就好了。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐