我正在使用Selenium Webdiver。我的測試案例是。如何使用selenium Webdriver處理Javascript單擊?
- 登錄到網站。
- 點擊通知鏈接。
現在所面臨的問題,而在通知鏈接點擊,具有HTML代碼如下: - :
/*1*/ driver.findElement(By.xpath("//a[@class='mTxt']")).click();
/*2*/ driver.findElement(By.cssSelector("div[class='topIcon notify']")).click();
/*3*/ driver.findElement(By.linkText("Notifications")).click();
/*4*/ driver.findElement(By.xpath("//div[@class='pNotifyCont dspN']")).click();
/*5*/ Actions mouse=new Actions(driver);
WebElement element=driver.findElement(By.xpath("//div[@class='pNotifyCont dspN']"));
mouse.moveToElement(element).click().build().perform();
Error : Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//a[@class='mTxt']"} Command duration or timeout: 7.56 seconds
<ul class="rghtSec fr menu logged"><li><a href="javascript:;">
<div class="topIcon notify"><span> </span></div>
<div class="mTxt">Notifications<span id="rJobCntr" class="rJobCntr"></span></div></a>
<div class="subMenu recommendTT">
<ul>
<li><a target="_blank" class="blob" id="blobId" href="http://jobsearch.naukri.com/notifications">
Fetching jobs you may apply for</a></li>
</ul>
我已經通過以下5種不同的方式嘗試
但這些方式都不能解決問題:(,誰能幫我解決這個問題嗎?
您的鏈接是否存在於iframe中? –
韓..但是..對不起..它不在iframe /框架集。所以我不能使用它。 –
請嘗試driver.findElement(By.xpath(「// a // div [@ class ='mTxt']」))。click(); –