1
votes

I have to select the value from the drop-down box but to select the value it needs mouse-over to open the pop-up.

I am using sendKeys("Body > Abdomen"). Let me know the correct way to select the value from drop-down box

Following the HTML Code for the second drop-down box :

<div id="bodypart_box_1">
<div style="position:absolute;left:185px;z-index: 20">
<ul class="parent">
<li>
<div id="main" class="mailval">events=Object { click=[1]}handle=function()
<input id="bodypart_1" class="bodypart error" type="text"  
onfocus="if($(this).hasClass('disabled')){$(this).blur();}" readonly="readonly"  
value="Select One" name="bodypart_1" title="">
<input id="actualBodypart_1" type="hidden" value="" name="actualBodypart_1">
</div>
<ul id="bodyPartList_1" class="top sub bodyPartList" style="display:   
block;">olddisplay="block"
<li class="">

<div class="mailval fly" title="Body" originaltitle="Body">Body</div>events=Object {   
click=[1], mouseover=[1]}handle=function()
<ul style="display: block;">olddisplay="block"
<li class="">

<div class="mailval " title="Body > Abdomen" originaltitle="Body > 
Abdomen">Abdomen</div>events=Object { click=[1], mouseover=[1]}handle=function()
</li>
<li class="">
3
This HTML won't render properly because many of the tags aren't closed, and much of the JavaScript is not written in the correct place (and thus is rendered as plain text). Also, what language are you using with the Selenium WebDriver? (e.g. JavaScript, Java, Ruby, C# or Python?) - James Dunn
I am using in Selenium WebDriver Java language. - user2943890

3 Answers

0
votes

The simple answer is to do something like this:

  1. Click on the div containing the select container to cause it to open by using Element.click() .
  2. Then, get the select "Option" elements as a List and iterate through it until you find the string match using el.getText() or el.getAttribute("id") or whatever.

I do something similar to this on my Etsy search example project, which shows the Etsy dynamic search as an example.

0
votes

Basically, you'll have to first move mouse to 'Menu item' drop-down and then move mouse to option which you want to select and then click on option.

For Ruby following is one line code:

driver.action.movet_to(el1).movet_to(el2).click.perform

I don't know about Java but you can apply above logic. I tried with following Java code, see if it works or modify it wherever required:

WebElement element1 = driver.findElement(By.linkText("Manage Channels")); 
WebElement element2 = driver.findElement(By.xpath("//li/a[contains(., \"Manage Channels\")]"))

Actions action = new Actions(driver);    
action.moveToElement(element1).moveToElement(element2).click().build().perform();
0
votes

You can do in two ways:

WebElement menu = driver.findElement(By.id("id"));
Actions builder = new Actions(driver);
builder.moveToElement(menu).moveToElement(driver.findElement(submenu)).click().build().perform();

Also you can click using JavascriptExecutor:

WebElement menu = ff.findElement(By.id("id"));
((JavascriptExecutor)ff).executeScript("$(arguments[0]).click();", menu);

You can change the code according to your HTML code. JavascriptExecutor's code won't work if JS is disabled in your browser.