这是我的HTML代码,请提供点击特定链接的任何建议,我尝试了所有替代方案,但没有任何工作。 请建议。
<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[B@2569a1ab" onclick="constructProcessParameter('feature','uniq_7151[B@2569a1ab','uniq_7151[B@2569a1ab','','','Metro E Equipment Fee','2985725')" onmouseover="getToolTip('Equipment Fee','Equipment Fee Configuration','Equipment Fee Configuration','uniq_7151[B@2569a1ab')" 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, 'B@24d742b9')]
//input[matches(@id, 'uniq_.*B@24d742b9')]
答案 0 :(得分:0)
您可以尝试其中一种
driver.findElement(By.xpath("//a[contains(text(), 'Equipment Fee Configuration')]"));
driver.findElement(By.cssSelector(".firstChild > li > a"));
答案 1 :(得分:0)
您可以尝试driver.FindElement(By.LinkText("Your link text here")).Click();
或
您可以在运行时获取链接文本并将其存储在字符串中,然后使用您的编程语言访问该链接。
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();
如果你只想声明响应`
,那么你也可以获得响应代码