Python所需功能错误
设置所需的功能(Python所需功能错误,python,eclipse,selenium,Python,Eclipse,Selenium,设置所需的功能(所需的\u caps)后,我的脚本出现错误。错误是 如果所需的功能为无: ^缩进错误:意外缩进 代码如下: import unittest from selenium import webdriver from appium import webdriver from appium import webdriver from selenium.webdriver.common import desired_caps from webdriver import WebDriver
所需的\u caps
)后,我的脚本出现错误。错误是
如果所需的功能为无:
^缩进错误:意外缩进 代码如下:
import unittest
from selenium import webdriver
from appium import webdriver
from appium import webdriver
from selenium.webdriver.common import desired_caps
from webdriver import WebDriver as Remote
class CNNEndToEnd(unittest.TestCase):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0.1'
desired_caps['deviceName'] = 'Samsung'
#desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')
desired_caps['appPackage'] = 'com.android.vending'
desired_caps['appActivity'] = '.AssetBrowserActivity'
print desired_caps
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def testACNNInstallAndLaunch(self):
print "**************************"
print "********APP INSTALL*******"
print "**************************"
print "here---------"
#appid = "com.cnn.mobile.android.phone"
if (self.driver.is_app_installed("com.cnn.mobile.android.phone")):
print "-----App ALready Installed"
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(CNNEndToEnd)
unittest.TextTestRunner(verbosity=2).run(suite)
完整错误消息:
Traceback (most recent call last):
File "/Users/manusimply/.p2/pool/plugins/org.python.pydev_5.8.0.201706061859/pysrc/_pydev_runfiles/pydev_runfiles.py", line 468, in __get_module_from_str
mod = __import__(modname)
File "/Users/manusimply/Desktop/Eclipse/CNN_PoC/CNN_New.py", line 2, in <module>
from appium import webdriver
File "/Users/manusimply/Desktop/Eclipse/Appium-Python-Client-0.2/appium/webdriver/__init__.py", line 19, in <module>
from webdriver import WebDriver as Remote
File "/Users/manusimply/Desktop/Eclipse/Appium-Python-Client-0.2/appium/webdriver/webdriver.py", line 15, in <module>
from selenium import webdriver
File "/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/__init__.py", line 18, in <module>
from .firefox.webdriver import WebDriver as Firefox # noqa
File "/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/firefox/webdriver.py", line 34, in <module>
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
File "/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/remote/webdriver.py", line 79
if desired_capabilities is None:
^
IndentationError: unexpected indent
ERROR: Module: CNN_New could not be imported (file: /Users/manusimply/Desktop/Eclipse/CNN_PoC/CNN_New.py).
回溯(最近一次呼叫最后一次):
文件“/Users/manusimply/.p2/pool/plugins/org.python.pydev_5.8.0.201706061859/pysrc/_-pydev_-runfiles/pydev_-runfiles.py”,第468行,位于从
mod=uuu导入(modname)
文件“/Users/manusimply/Desktop/Eclipse/CNN\u PoC/CNN\u New.py”,第2行,在
从appium导入webdriver
文件“/Users/manusimply/Desktop/Eclipse/Appium-Python-Client-0.2/Appium/webdriver/_init__.py”,第19行,在
从webdriver以远程方式导入webdriver
文件“/Users/manusimply/Desktop/Eclipse/Appium-Python-Client-0.2/Appium/webdriver/webdriver.py”,第15行,在
从selenium导入webdriver
文件“/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/\uuuuuuu init\uuuuuuuuuu.py”,第18行,在
从.firefox.webdriver将webdriver导入为firefox#noqa
文件“/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/firefox/webdriver.py”,第34行,在
从selenium.webdriver.remote.webdriver将webdriver作为RemoteWebDriver导入
文件“/Users/manusimply/Desktop/Eclipse/selenium-3.4.3/selenium/webdriver/remote/webdriver.py”,第79行
如果所需的_功能为无:
^
缩进错误:意外缩进
错误:无法导入模块:CNN_New(文件:/Users/manusimply/Desktop/Eclipse/CNN_PoC/CNN_New.py)。
您应该使用DesiredCapabilities对象,而不仅仅是要实现的功能列表。这会让你的生活更轻松。如下所示初始化变量,然后将您的功能添加到该变量中
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
desired_caps = DesiredCapabilities.CHROME
有关在python中初始化webdriver的更多详细信息,请参阅此链接:
另外,请确保对每个功能使用正确的命名约定。此处列出了功能及其名称:
希望这能有所帮助:)
也适用于所需的_上限。我建议加入udid并使用完整的appActivity路径。您的问题是什么?抱歉,因为我是这个社区的新手,我对提问没有正确的想法。。从上面的代码中,我无法运行我的脚本。这应该会让你继续提问。请解释你希望看到什么,你看到了什么,以及你做了什么来试图解决你的问题。谢谢,我在上面运行代码时遇到了问题。谢谢,设置了所需的功能,但问题仍然存在。查看你的stacktrace,您可能没有正确安装selenium。您是否遵循了上的说明??该网站应该告诉你如何启动,你能帮我创建我正在尝试的驱动程序对象吗?机器人正在显示
code
AttributeError:'CNNEndToEnd'对象没有属性“driver”code
self.driver=webdriver.android('',需要的上限)
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0.1'
desired_caps['deviceName'] = 'Samsung'
#desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')
desired_caps['appPackage'] = 'com.android.vending'
desired_caps['appActivity'] = '.AssetBrowserActivity'
**print(desired_caps)**