1. IE没法正常启动javascript
1)Security 三个设置成同样的,包括是否启用保护模式也要同样css
2)页面缩放比例要设置为100%html
2.Firefox启动后为中文环境,但但愿为英文环境java
Firefox driver每次会启动一个彻底干净的浏览器,profile为空的。可更改profile为当前profile,这样不只使用的就是当前default的环境,同时也就可以启动plug-innode
profile = webdriver.FirefoxProfile(r'C:\Users\Samsung\AppData\Roaming\Mozilla\Firefox\Profiles\xpttkqws.default-1427164221316')
self.browser = webdriver.Firefox(profile)jquery
3.webElement点击没有响应web
使用js模拟点击浏览器
compose = self.find_element(self.user_browser, *self.__menu_Compose_loc)
self.user_browser.execute_script('arguments[0].click();', compose)测试
4.经过Send_keys()实现文件上传,Chrome正常但,IE只弹出选择文件对话框ui
将IEdriver更新为2.53.1正常了,2.53.0出现问题,但以前的老版本也没有问题。经此IEDriver各个版本之间仍是有必定差别
好比:
老版本(已不能确认版本号大概是15年版本)中须要self.user_browser.execute_script("arguments[0].style.opacity='1';", input_attach),以后才能对元素执行send_keys()要否则报错
ElementNotVisibleException: Message: Element is not displayed
新版本不须要
5. Firefox在48版本以前不须要使用单独的webdriver, 但须要禁止Firefox的自动更新功能,不然Firefox更新后将致使浏览器不能正常启动。
6. Debug是想要输出html标签内容 <span>Compose</span>, 使用webelement.get_attribute("innerText") 输出Compose.
7. 使用HTMLRunner输出report
def run(self,testSuite = None): name_time = datetime.datetime.now().strftime("%Y%m%d%H%M%S") file_name = self.report_dir + str(name_time) +"_result.html" fp = open(file_name, "wb") runner = HTMLTestRunner(stream=fp, title="TestResult", description="Test result of compose mail: ") print "**knoxPortal Msg > testControl > run : Run start.." runner.run(testSuite) fp.close() print "**knoxPortal Msg > testControl > run : Run successfully.."
8. 使用WebElement.findElement(By by) 是查找element的子元素,可是使用xpath时却会查找全局
List<WebElement> findElements(By by) Find all elements within the current context using the given mechanism.
When using xpath be aware that webdriver follows standard conventions:
a search prefixed with "//" will search the entire document, not just the children of this current node.
Use ".//" to limit your search to the children of this WebElement.
This method is affected by the 'implicit wait' times in force at the time of execution.
When implicitly waiting, this method will return as soon as there are more than 0 items in the found collection, or will return an empty list if the timeout is reached.
9.xpath查找不包含某个子元素的当前元素
<li id="lpm_40611_0">
<a>
<ul class="prtit_area clear_both">
<li class="date">当天购</li>
</ul>
</a>
<p class="btn_cart">
<a>购物车</a>
</p>
</li>
<li id="lpm_40611_1">
<a>
<ul class="prtit_area clear_both">
<li class="new">新品</li>
</ul>
</a>
<p class="btn_cart">
<a>购物车</a>
</p>
</li>
<li id="lpm_40611_2">
<a>
<ul class="prtit_area clear_both">
<li class="new">新品</li>
</ul>
</a>
<p class="btn_cart">
<a>到货通知</a>
</p>
</li>
<li id="lpm_40611_3">
<a>
<ul class="prtit_area clear_both"> ::after </ul>
</a>
<p class="btn_cart">
<a>当天购</a>
</p>
</li>
如今须要查找没有分析当天购标签,可是有购物车标签的购物车元素
//ul[@class='prtit_area clear_both' and not(*[@class='date'])]//ancestor::li[@id]//a[contains(text(),'购物车')]
//ul[@class='prtit_area clear_both' and (not(li[@class='date']) or not(li))]//ancestor::li[@id]//a[contains(text(),'购物车')]
对于以上两个的区别not(li[@class="date"])会查找有li标签可是class不为date的ul标签
10. selenium2library在使用JavaScript时是使用关键字 execute JavaScript ,这个关键字只支持输入一个纯javascript的list,而底层的selenium库中咱们在使用的时候更经常使用的是使用executejavascript("arguments[0].ckicl();",weblement),因此我么须要本身封装一下这个关键字
#原关键字
def execute_javascript(self, *code): js = self._get_javascript_to_execute(''.join(code)) self._info("Executing JavaScript:\n%s" % js) return self._current_browser().execute_script(js)
#自定义关键字
def execute_javascript_with_args(self, code,*args):
return self._current_browser().execute_script(code,*args)
#Java public void scrollToView(WebElement e) throws Exception { executeJS("window.scrollTo(0," + e.getLocation().y + ")"); executeJS("arguments[0].scrollIntoView(true);", e); }