是否有可能使用LINKTEXT定位在這段代碼鏈接文字中硒的webdriver
我用driver.findElement(By.linkText("welcome")).click();
但沒有奏效。 請幫助....
<div class="back-to">
<a class="button blue" href="javascript:history.back()">welcome</a>
</div>
是否有可能使用LINKTEXT定位在這段代碼鏈接文字中硒的webdriver
我用driver.findElement(By.linkText("welcome")).click();
但沒有奏效。 請幫助....
<div class="back-to">
<a class="button blue" href="javascript:history.back()">welcome</a>
</div>
的LINKTEXT應該在這種情況下工作。要不試試下面的替代品(並請提供足夠的implicit timeout給硒sufficent的時間來檢測元素):
1.使用xpath
,點擊元素a,具有精確的innerHTML /文本「上歡迎':
driver.findElement(By.xpath("//a[.='welcome']")).click();
2 - 使用JavascriptExecutor
點擊與確切的innerHTML /文本作爲元素的 '歡迎':
((JavascriptExecutor)driver).executeScript("arguments[0].click();", driver.findElement(By.xpath("//a[.='welcome']")));
3-使用partialLinkText
點擊與部分文本 '歡迎'
driver.findElement(By.partialLinkText("welcome")).click();
的鏈接,這應該是足夠了:
driver.find_element_by_xpath('//a[@class="button blue"]').click();
@HelpingHands:只是好奇。你能指定它不工作的原因嗎? – 2014-12-19 10:47:09
@Prashanth得到了什麼錯誤/異常? – Subh 2014-12-19 11:01:22
@RupeshShinde - 對不起。我錯了。其實我在這裏寫了另一個問題的答案。 – 2014-12-19 11:13:05