如何使用selenium webdrive java选择span标记中存在的下拉选项?

时间:2017-03-03 06:45:14

标签: javascript selenium selenium-webdriver

下拉主文件在DIV和IMG标签中都有ID,我可以使用其中任何一个点击下拉主页,但是,我无法点击下拉选项,请帮忙。

下拉列表的源代码:

<div id="drop_mainmenu" tabindex="0">Navigator

<img id="mainmenu_downarrow" border="0" class="ArrowImg" alt="" title="" src="/jde/share/images/menu_l23_button_dropdown_dwn.png" onmouseover="this.src='/jde/share/images/menu_l23_button_dropdown_ovr.png'" onmousedown="this.src='/jde/share/images/menu_l23_button_dropdown_dwn.png'" onmouseout="this.src='/jde/share/images/menu_l23_button_dropdown_dwn.png'" data-pin-nopin="true"><br>
</div>

下拉选项之一的源代码:

<span id="fldnode140398" style="color: #000000;font-style: normal;" title="Task Type:Task View, Fastpath Code: TV:140">Christie's Dubai</span>

1 个答案:

答案 0 :(得分:0)

尝试放置一些wait并尝试:

driver.findElement(By.id("mainmenu_downarrow")).click();
Thread.sleep(3000L);
driver.findElement(By.xpath(".//span[contains(text(), 'Christie's Dubai')]")).click();
  

OR

driver.findElement(By.id("mainmenu_downarrow")).click();  
Thread.sleep(3000L); 
driver.findElement(By.xpath(".//span[contains(@id, 'fldnode140398')]")).click();
  

OR

driver.findElement(By.id("mainmenu_downarrow")).click();  
Thread.sleep(3000L); 
driver.findElement(By.xpath(".//span[starts-with(@id, 'fldnode')]")).click();