我使用简单命令运行文件start_selenium.cmd
...
python selenium.py
如果我要在实际的命令行中运行它,我会得到所有预期的print
语句。但是使用.cmd文件来执行此脚本,我得到的错误和警告与我的print
语句混合在一起。这包括管道错误和NOT IMPLEMENTED错误。
无论如何要在不压制我的打印语句的情况下抑制这些错误?这台计算机实际上是作为Selenium测试的奴隶运行的,所以我不想让返回尽可能干净。这也是我设置.cmd文件来触发Python脚本的原因。否则我之前没有使用过这种类型的执行。
这里是NOT IMPLEMENTED错误......
[10828:8364:0318/174026:ERROR:chrome_views_delegate.cc(185)] NOT IMPLEMENTED
[10828:8364:0318/174026:ERROR:desktop_root_window_host_win.cc(760)] NOT IMPLEMENTED
[10828:8364:0318/174026:ERROR:desktop_root_window_host_win.cc(760)] NOT IMPLEMENTED
和管道错误......
[7784:10788:0318/174746:ERROR:ipc_channel_win.cc(405)] pipe error: 232
我更新了我的chromedriver和selenium作为修复程序并仍然得到相同的错误。
这是python脚本的一个非常基本的例子(删除最多):
...
from selenium import webdriver
import time
...
def dom_activity(driver, browsname):
start_time = time.clock()
max_tries = 5
attempted_tries = 1
while realpath not in driver.current_url and max_tries > 0:
try:
driver.get(realpath)
driver.maximize_window()
print 'PASS - ' + realpath + ' accessed using : ' +browsname
tests['pass'] += 1
except:
max_tries -= 1
attempted_tries += 1
time.sleep(1)
continue
break
print 'attempts at homepage access = ' + str(attempted_tries) + '\n'
tests['exec'] += 1
driver.switch_to_active_element()
while realpath in driver.current_url:
signinid = 'blah'
max_tries = 5
attempted_tries = 1
try:
driver.find_element_by_id(signinid).click()
print 'PASS - access to Sign In page using : ' +browsname
tests['pass'] += 1
except:
if max_tries == 0:
print 'FAIL - access to Sign In Page using : ' +browsname
tests['fail'] += 1
break
max_tries -= 1
attempted_tries += 1
time.sleep(1)
continue
break
print 'attempts at signing in = ' + str(attempted_tries) + '\n'
tests['exec'] += 1
try:
driver.find_element_by_id('blah2').send_keys(user['name'])
driver.find_element_by_id('blah3').send_keys(user['pass'])
driver.find_element_by_id('blah4').click()
except:
print 'FAIL - processing Sign-In after keys and click, using : ' + browsname
cur_url = driver.current_url
if '/blah' in cur_url:
print 'PASS - Signed in with : ' + browsname
tests['pass'] += 1
else:
print 'FAIL - Not Signed in with : ' + browsname + '\n the url after login is : ' + cur_url
tests['fail'] += 1
tests['exec'] += 1
print browsname + ' took only ' + str(time.clock() - start_time) + ' seconds \n'
driver.close()
...
chromedriver = webdriver.Chrome()
dom_activity(chromedriver, 'Chrome')
...
print 'blah' + 'results'