2013-10-31 39 views
1

我有一個塊,「類別」。 該塊有一個隱形的配置鏈接(配置鏈接:<a class="contextual-links-trigger" href="#">Configure</a>) 當我手動移動鼠標到這個塊時,配置鏈接變爲<a class="contextual-links-trigger contextual-links-trigger-active" href="#">Configure</a>並且配置圖標顯示(基於新類「contextual-links-trigger-active」)。 當我點擊配置圖標,鏈接「編輯視圖」將顯示。 (見圖片)如果使用java webdriver不會顯示隱形鏈接

圖像鏈接:https://www.facebook.com/photo.php?fbid=448612048582483&set=a.152871061489918.29073.100003010769102&type=1&theater

我想點擊鏈接 「編輯觀點」 使用的Java Web驅動程序。 我用下面的代碼顯示的配置圖標,但沒有成功:

Actions builder = new Actions(driver); 
     builder.moveToElement(driver.findElement(By.xpath(xpath))).perform(); 

請給我一些想法。謝謝!

回答

0

可以使用JavascriptExecuter點擊隱形鏈接,

((JavascriptExecutor)driver).executeScript("$('.contextual-links-trigger').click();"); 

那麼你可以等待編輯視圖的知名度和使用點擊

new WebDriverWait(driver,30).until(ExpectedConditions.visibilityOfElementLocated(By.linkText("Edit view"))).click(); 
+0

感謝您的想法。我用它來處理我的情況。它運作良好。這裏是我的代碼: JavascriptExecutor js =(JavascriptExecutor)driver; (「document.querySelector('#」+ block_id +「.contextual-links-trigger')。classList.add('contextual-links-trigger-active');」); (包含(@id,''+ block_id +'')] // a [contains(@class,' 。語境鏈接觸發活性')]「)))點擊(); –

+0

很高興它幫助..在stackoverflow其自定義接受答案或upvote,如果它的作品,以便它會幫助其他人誰在今後提到這.. – Amith