2014-09-25 67 views
0

我想單擊一個下拉元素,點擊鼠標懸停後隱藏元素和隱藏元素顯示後出現的元素。我使用硒web驅動程序,請幫助我如何可能。我想單擊一個下拉元素

我嘗試使用動作類和JSExecutor但未能得到了解決

回答

0

嘗試使用選擇這裏。

例如:

driver.get( 「http://example.com」);
Select select = new Select(driver.findElement(By.name(「value」)));
select.selectByIndex(1);

根據下拉列表/選項位置更改索引值。

+0

首先,我必須尋找隱藏的元素,然後我必須點擊它,點擊隱藏元素生成一個下拉上,我要click..can妳告訴我完整的代碼... select類只會從下拉菜單中選擇代碼。 – 2014-09-25 12:02:50

+0

我可以有更多關於應用程序的細節嗎?網址或類似的網頁將會很好。 – 2014-09-25 12:10:03

0

試試這個:

Select select = new Select(driver.findElement(By.tagName("select"))); 
select.selectByVisibleText("Text"); 

如果你想獲得更多有用的信息,請提供一些HTML代碼或 你如何試圖單擊下拉:)

的元素問候,謝爾蓋·

0
public class Mousehovers { 

    public static void main(String[] args) throws InterruptedException { 
    WebDriver driver = new FirefoxDriver(); 
    driver.get("http://www.sample.com"); 

    Actions actions = new Actions(driver); 
    WebElementmenuHoverLink=driver.findElement(By.xpath("//a[contains(text(),'xx')]")); 
    actions.moveToElement(menuHoverLink).perform(); 
    Thread.sleep(5000); 

    List<WebElement>menuHoverLink1 = driver.findElements(By.xpath("xxxxxxx")); 
    System.out.println(menuHoverLink1.size()); 

    for(int i=0;i<menuHoverLink1.size();i++){ 
     System.out.println(menuHoverLink1.get(i).getText()); 

    } 
    } 
    } 
+0

如果您對上述代碼感到滿意,請選擇上部箭頭「此答案很有用」 – DSL 2014-09-26 05:10:40

+1

滿足您的Thread.sleep(5000)?不要這樣想。 – JoriO 2014-09-26 08:44:47

+0

我同意u Thread.sleep(5000)更多,但沒有Thread.sleep()它是否在控制檯中打印文本?我不認爲。我試圖讓文本沒有Thread.sleep(),但我沒有得到文本。如果你希望文本至少放入Thread.sleep(1000)。如果你用Thread.sleep()取出文本,請讓我知道我會盡力做到這一點。 – DSL 2014-09-26 14:32:19