2015-05-22 61 views
-1

如何驗證與下面的HTML錨標記asscoiated onclick事件的錨標籤爲:據如何驗證`在JavaScript onclick`事件中使用硒的webdriver

<div class="itp-sb-left" style="float:left; width:100%; border:solid 1px #cccccc; padding:2px 0 2px 5px;"> 
      <a title="Submit to Facebook" target="_parent" 
      onclick="window.open('https://www.facebook.com/sharer.php? 
       s=100&p[title]= 
       Singh&p[summary]=%27ll+try+to+describe+some+of+the+ideas+here.+Matrix+factorization+techniques+and+ensemble+methods+are+perhaps+the+algorithms+most+often+discussed+in+connection+with+the+Netflix+Prize%2C+but+a+lot+of+othe...&p[url]=http%3A%2F%2Fwww.jobma.com%2F1946&&p[images][0]=http%3A%2F%2Fwww.jobma.com%2Fpitcher%2FPhoto%2Fthumb_profile-1432116605.jpg', 'sharer', 'toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)"> 


<img alt="Submit to Facebook" src="http://www.jobma.com/images/facebook.png"/> 
</a> 
+2

請閱讀[this](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist?lq=1) – Saifur

回答

0

我瞭解你想驗證以下的onclick事件JS:

window.open('https://www.facebook.com/sharer.php? 
       s=100&p[title]= 
       Singh&p[summary]=%27ll+try+to+describe+some+of+the+ideas+here.+Matrix+factorization+techniques+and+ensemble+methods+are+perhaps+the+algorithms+most+often+discussed+in+connection+with+the+Netflix+Prize%2C+but+a+lot+of+othe...&p[url]=http%3A%2F%2Fwww.jobma.com%2F1946&&p[images][0]=http%3A%2F%2Fwww.jobma.com%2Fpitcher%2FPhoto%2Fthumb_profile-1432116605.jpg', 'sharer', 'toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)"> 

由於這在新窗口中被打開,所以你可以驗證的URL在新窗口中打開如下:

ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles()); 

driver.switchTo().window(tabs.get(0)); 
String urlInNewTab = driver.getCurrentUrl(); 
Assert.assertEquals(urlInNewTab, 'YOUR_EXPECTED_URL_HERE);