在用户的根目录找到了
已经换种方式解决
class mytest(unittest.TestCase):
##初始化工作
def setUp(self):
pass
def tearDown(self):
self.dr.quit()
def testfun(self):
pass_1 = False
try:
self.dr.find_element_by_id('11')
print('pass')
except:
pass_1 = True
print(pass_1)
if pass_1 == True:
self.assertIsNone(None, '存在wulh发起的任务,Fail')
else:
self.assertIsNone(not None, '存在wulh发起的任务,Fail')
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(mytest)
unittest.TextTestRunner(verbosity=2).run(suite)
self.assertIsNone(self.dr.find_element_by_name(taskname_2),'存在发起的任务,Fail')
当 self.dr.find_element_by_name(taskname_2) 找不到时直接脚本报错,报错如下,找不到时不是刚好验证不存在,不应该是 pass 吗?
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
这我就不懂了。。。
直接用'WEBVIEW',不用改试下
可自行在脚本中切换
self.dr.switch_to.context('WEBVIEW') #切换至webview
self.dr.switch_to.context('NATIVE_APP') #切换成原生
可以使用装饰器:
def getImage(function):
@wraps(function)
def get_ErrImage(self,*args, **kwargs):
try:
result = function(self,*args, **kwargs)
except:
timestr = time.strftime("%Y-%m-%d_%H_%M_%S")
self.dr.get_screenshot_as_file('E:\\Appium\\Mailchat\\image\\getscreen\\%s %s.png' %
(function.__name__timestr))
else:
logging.info (" %s 脚本运行正常" %
(function.__name__)
)
return result
return get_ErrImage
使用:
class myInitiate_addOppionTest(unittest.TestCase):
def setUp(self):
public.setUp.setUp(self)
def tearDown(self):
self.dr.quit()
@getImage
def test_myInitiate_addOppion(self):
go_loginPage(self) #访问登录页
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(myInitiate_addOppionTest)
unittest.TextTestRunner(verbosity=2).run(suite)
tks,确实是因为内有 return 导致的,将 js 语句改为如下就可以了:
js = 'return document.getElementById("元素ID").value'
感谢回复,试了 self.driver.save_screenshot() 这个方法也不行,没有保存到指定路径
请问楼主解决该问题了吗?求分享
@doctorq 请教下,下面这种报错是什么情况呢?
十二月 29, 2015 2:30:26 下午 com.android.chimpchat.adb.AdbChimpDevice$2 step
信息: Monkey Command: tap 481 951.
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implWrite(Unknown Source)
at sun.nio.cs.StreamEncoder.write(Unknown Source)
at java.io.OutputStreamWriter.write(Unknown Source)
at java.io.BufferedWriter.flushBuffer(Unknown Source)
at java.io.BufferedWriter.flush(Unknown Source)
at com.android.chimpchat.ChimpManager.sendMonkeyEventAndGetResponse(ChimpManager.java:187)
at com.android.chimpchat.ChimpManager.sendMonkeyEvent(ChimpManager.java:235)
at com.android.chimpchat.ChimpManager.tap(ChimpManager.java:330)
at com.android.cts.tradefed.testtype.monkey.MonkeyTapEvent.fireEvent(MonkeyTapEvent.java:34)
at com.android.cts.tradefed.testtype.monkey.Monkey.nextRandomEvent(Monkey.java:41)
at com.android.cts.tradefed.testtype.MonkeyTest.run(MonkeyTest.java:152)
at com.android.tradefed.invoker.TestInvocation.runTests(TestInvocation.java:590)
at com.android.tradefed.invoker.TestInvocation.prepareAndRun(TestInvocation.java:400)
at com.android.tradefed.invoker.TestInvocation.performInvocation(TestInvocation.java:332)
at com.android.tradefed.invoker.TestInvocation.invoke(TestInvocation.java:133)
at com.android.tradefed.command.CommandScheduler$InvocationThread.run(CommandScheduler.java:362)
非常需要该书,望赠,QQ:839220822
第 3 步的点击开始按钮需要先启动模拟器或者电脑有连接真机才行,我之前以为会自己启动,搞了好久,好丢人
好像是我添加的 app 路径含有中文导致的,换成英文路径正常了
提示如下图这个报错,我是菜鸟,能否详细说明下怎么解决,tks