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); }