我有一个现有的python模块,其名称为foo-bar.py
更改模块名称是我希望避免的,因为模块是共享的,我将不得不追查它使用的所有位置,以便我的特殊情况可以工作.
有没有办法加载名称中包含通常被禁止的' - '的模块?
(我确实理解这不是最佳做法.但对于这种情况,我宁愿不重新设计和测试更大的应用程序.我也不认为我的公司主人会赞成我花时间实施这样的改变.)
我一定在想这个错误.
我想在我使用Webdriver/Selenium 2访问的页面上获取元素的内容,在本例中为formfield
这是我破碎的代码:
Element=driver.find_element_by_id(ElementID)
print Element
print Element.text
Run Code Online (Sandbox Code Playgroud)
这是结果:
<selenium.webdriver.remote.webelement.WebElement object at 0x9c2392c>
Run Code Online (Sandbox Code Playgroud)
(注意空白行)我知道该元素有内容,因为我只是使用.sendkeys将它们填充到上一个命令中,我可以在脚本运行时在实际网页上看到它们.
但我需要将内容恢复为数据.
我该怎么做才能读到这个?优选地,以通用方式使得我可以从各种类型的元素中提取内容.
(编辑:也许这个错误意味着我错了.这是否表示我的CLIENT的连接池已满?或者SERVER的连接池已满,这是我的客户端给出的错误?)
我试图http使用python threading和requests模块同时发出大量请求.我在日志中看到这个错误:
WARNING:requests.packages.urllib3.connectionpool:HttpConnectionPool is full, discarding connection:
Run Code Online (Sandbox Code Playgroud)
如何增加请求的连接池大小?
我正在为Web应用程序编写测试.某些命令会拉出对话框,这些对话框具有可见的控件,但暂时不可用.(它们是灰色的,但是webdriver仍然看到它们可见).
我如何告诉Selenium等待元素实际可访问,而不仅仅是可见?
try:
print "about to look for element"
element = WebDriverWait(driver, 10).until(lambda driver : driver.find_element_by_id("createFolderCreateBtn"))
print "still looking?"
finally: print 'yowp'
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的代码,但它在可用之前"看到"了按钮,基本上是在假定的"等待"之后收费.
请注意,我可以在代码中填充十秒钟而不是这样,代码将正常工作,但这是丑陋,不可靠和低效的.但它确实证明问题只是"点击"命令在控制的可用性之前飙升.
我需要一个自纪元以来毫秒(ms)的单个时间戳.这应该不难,我相信我只是缺少一些datetime类似的方法.
实际上,微秒(μs)粒度也很好.我只需要1/10秒的时间.
例.我有一个事件发生在每750毫秒,让我们说它检查灯是打开还是关闭.我需要记录每个检查和结果并稍后查看,以便我的日志需要如下所示:
...00250 Light is on
...01000 Light is off
...01750 Light is on
...02500 Light is on
Run Code Online (Sandbox Code Playgroud)
如果我只有完整的第二粒度,我的日志将如下所示:
...00 Light is on
...01 Light is off
...01 Light is on
...02 Light is on
Run Code Online (Sandbox Code Playgroud)
不够准确.
我相信这很容易,我只是错过了一两个角色.
我需要在文件中搜索特定的术语,当我找到它时,我需要在该行中添加一些内容.而且我想在比赛的每一行都这样做.
要做一次,我可以这样做:
/Thing to find/s/$/ Stuff to append/
Run Code Online (Sandbox Code Playgroud)
简单.如果我的"找到的东西"在行的末尾,我可以这样做:
%s/\(Thing to find\)$/\1 Stuff to append/
Run Code Online (Sandbox Code Playgroud)
在每个匹配的行上做同样的事情
但是我如何在每一行上做第一件事呢?
我想我能做到
%s/\(Thing to find.*\)$/\1 Stuff to append/
Run Code Online (Sandbox Code Playgroud)
但是,如果找到的东西不止一次就行了,那就会让人觉得笨拙并且会让它变得更加复杂.
我认为必须有一种方法可以在任何地方进行我的第一次搜索,但是我在撰写简明扼要的描述以进行谷歌搜索时遇到了麻烦.
那么强大的Stackers,有人想让书呆子给我打两个字节的解决方案吗?
我有一个调用python方法的机器人框架测试套件.我希望该python方法在不失败测试的情况下将消息返回到控制台.具体来说,我正在尝试计划一个过程.
我可以使用"raise"将消息返回到控制台,但同时未通过测试.
def doSomething(self, testCFG={}):
'''
Do a process and time it.
'''
testCFG['operation'] = 'doSomething'
startTime = time.time()
response=self.Engine(testCFG)
endTime = time.time()
duration = int(round(endTime-startTime))
raise "doSomething took", duration//60 , "minutes and", duration%60, "seconds."
errmsg = 'doSomething failed'
if testCFG['code']: raise Exception(errmsg)
Run Code Online (Sandbox Code Playgroud)
或者我可以使用"打印"将消息返回到日志文件并报告而不会使测试失败,但该信息仅在报告中可用,而不是在控制台中.
def doSomething(self, testCFG={}):
'''
Do a process and time it.
'''
testCFG['operation'] = 'doSomething'
startTime = time.time()
response=self.Engine(testCFG)
endTime = time.time()
duration = int(round(endTime-startTime))
print "doSomething took", duration//60 , "minutes and", duration%60, "seconds."
errmsg = 'doSomething …Run Code Online (Sandbox Code Playgroud) 我确信这已经得到了解答,但对谷歌来说查询有点过于复杂.
简而言之,我试图从一些代码中删除许多弃用的方法.所以我正在浏览文件,当我看到一个我要删除的方法时,我将删除每一行,直到我看到一行以制表符开头,然后是字符串"def".
我在想VIM应该让我创建一个简单的宏来做到这一点,但诀窍是逃避我.
这是我要删除的东西.
def Method_to_Delete(self):
"""
@return Control ID :
@author
"""
results = {}
results['xx'] = "thingy"
results['yy'] = 'thingy2'
return results
def Method_to_Keep(self):
"""
This is a method that does something wonderful!!!
@return Control ID :
@author
"""
results = {}
results['xxx'] = "WhooHoo!"
results['yyy'] = 'yippee!!'
return results
Run Code Online (Sandbox Code Playgroud)
我希望将光标放在"def Method_to_Delete"的行上并做一些将删除但不包括"def Method_to_Keep"的内容
必须有比多个"dd"命令更好的方法.
我知道我可以使用这种格式$ {dict ['KEY']}从字典对象访问单个元素.像这样:
| | Log | ${dict['KEY']} |
Run Code Online (Sandbox Code Playgroud)
我可以像这样设置一个常规的旧标量:
| | ${scalar}= | RFKeyword | "Yowp"
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试设置这样的字典元素
| | ${dict['KEY']}= | RFKeyword | "Yowp"
Run Code Online (Sandbox Code Playgroud)
我在变量中得到"RFKeyword","Yowp",而不是处理"Yowp"时RFKeyword产生的结果,就像我这样做
| | ${scalar}= | RFKeyword | "Yowp"
Run Code Online (Sandbox Code Playgroud)
请帮助
应该是一个简单的问题.如何在jsDom对象中设置宽度?
jsdom.env({
url:'http://testdatalocation',
scripts: ['http://code.jquery.com/jquery.js'],
done: function(errors, tstWindow) {
console.log(tstWindow.innerWidth);
};
}
});
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何让"innerWidth"成为1024以外的任何东西