2014-02-18 27 views
0

我需要點擊「數據庫」按鈕。我試試這個代碼:如何使用webdriver的找到按鈕?

driver.switchTo().frame("frame_content"); 
     wait.until(visibilityOfElementLocated(By.id("topmenucontainer"))); 
     driver.findElement(By.linkText("server_databases.php?token=650c2ac770f7d54449d462b18ddd6a01")); 

但即使提流通環節的不幫我,我有例外:

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"partial link text","selector":"server_databases.php?token=65... 

我做錯了嗎?我怎樣才能用XPath礦石來做到這一點? DB_button

+0

Java不是JavaScript的。 –

+1

但它的Java與硒 –

回答

1

試試這個:

driver.findElement(By.xpath("//a[contains(@href,'server_databases.php?token=')]")); 

您的令牌可每次生成所以讓我們發現,如果含有局部環節。

+0

非常感謝!有用 –

0

部分鏈接文字是指<a ...></a>標籤之間的文字。您正在嘗試匹配href上的鏈接文本,而不是鏈接文本本身。

+0

對不起,這是一個從絕望的webdriver)我嘗試第一個'By.linkText'。它也沒有工作。 –

1

你似乎是使用部分鏈接文本雖然該鏈接不會出現有任何文字。我想你想使用像CSS選擇器和使用href屬性。

driver.findElementBy(By.cssSelector("[href*='server_databases.php?token=650c2ac770f7d54449d462b18ddd6a01']")) 
0

正如理查德已經提到的,你應該提到的鏈接文本是對用戶可見,即,它顯示在screen.I'm確保上述解決方案的鏈接文字工作,但知道這是重要的,爲什麼你的代碼沒有工作。

所以更換,

driver.findElement(By.linkText("server_databases.php?token=650c2ac770f7d54449d462b18ddd6a01")); 

driver.findElement(By.linkText("Databases")); 
0

這將做到這一點。

driver.findElement(By.xpath("//a[contains(@href,'server_databases.php?token=')]")); 

driver.findElement(By.xpath("/html/body/div[2]/ul/li/a")); 
相關問題