2016-03-03 52 views
1

這裏是我的HTML代碼,請提供任何建議以點擊特定的鏈接,我嘗試了所有的選擇,但沒有任何工作。 請請建議。如何點擊selenium中的鏈接網絡驅動程序

<tr> 
<td width="170" valign="top" style="word-wrap:break-word; word-break:break-all;"> 
<div id="ServAndFeature" class="left"> 
<h2 style="width: 150px;">Services and Features</h2> 
<ul class="service"> 
<input id="BVECheck" type="hidden" value="Metro E EDI" name="BVECheck"> 
<li> 
<li> 
<li> 
<li> 
<li> 
<li> 
<li class="current"> 
<li> 
<b>Equipment Fee</b> 
<ul class="firstChild" name="/Equipment Fee Configuration/"> 
<li> 
<a id="uniq_7151[[email protected]" onclick="constructProcessParameter('feature','uniq_7151[[email protected]','uniq_7151[[email protected]','','','Metro E Equipment Fee','2985725')" onmouseover="getToolTip('Equipment Fee','Equipment Fee Configuration','Equipment Fee Configuration','uniq_7151[[email protected]')" href="#">Equipment Fee Configuration</a> 
</li> 
</ul> 
<input id="BVECheck" type="hidden" value="Metro E Equipment Fee" name="BVECheck"> 
</li> 
<li> 
<li> 

我嘗試下面的方法:

//img[contains(@title,'Selected Service Order for Edit')] 

//a[contains(@href,'UNI:10/100')]/img; 
//*[@id='ServAndFeature']/ul/li[2]/ul/li/a 
css= a[href*='Equipment Fee Configuration'] 
xpath = "//a[text()='Equipment Fee Configuration']" 
ul.service li:nth-child(8) ul > li a 
//a[starts-with(@id, 'uniq_') and contains(@id, '[email protected]')] 
//input[matches(@id, 'uniq_.*[email protected]')] 
+0

任何回溯? – Andersson

+0

我們有4個鏈接是在同一個頁面下的同一個頁面中的....我試圖點擊第4個鏈接,它在li [8]下面,但是每次點擊li [1]鏈接 – prem

+0

我的意思是,當你嘗試用你的代碼點擊鏈接時,檢測到任何錯誤? – Andersson

回答

0

你可以試試這些

driver.findElement(By.xpath("//a[contains(text(), 'Equipment Fee Configuration')]")); 
driver.findElement(By.cssSelector(".firstChild > li > a")); 
+0

我已經嘗試了所有的方法,但仍然存在相同的問題,即使我試圖給絕對xpath,而不是點擊在4個超鏈接上點擊第一個。 – prem

+0

/html/body/form/div/div [2]/div/table [2]/tbody/tr [2]/td/table/tbody/tr [2]/td [1]/div/ul/li [8]/UL/LI /一 – prem

0

一個你可以嘗試driver.FindElement(By.LinkText("Your link text here")).Click();

你可以得到林k文本,並將其存儲在一個字符串中,然後使用編程語言訪問該鏈接。

string url= driver.FindElement(By.XPath("xpath or CSS selector as instructed").getAttribute("href"); 

,然後編寫代碼來訪問這個

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); 
     webRequest.AllowAutoRedirect = true; 
     HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); 

這就是你如何能得到響應代碼,以及如果要斷言只有response`

相關問題