Quality Testing

Quality is delighting customers

multiple drop down have same value and select same value from each drop down

Hi All,

I have a situation, where i have to select same value / different value from drop downs having same values in each. I am able to select value from first drop down but from second drop down i am not.

Please check the code i have written below.

public void clickDropdownByIdSelectValue(String inputid, String valuetotext){
driver.findElement(By.xpath("//input[@id='"+inputid+"']/parent::*//img")).click();
new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[contains(@class,'x-combo-list-item')]/parent::*/div[text()='"+valuetotext+"']")));
driver.findElement(By.xpath("//div[contains(@class,'x-combo-list-item')]/parent::*/div[text()='"+valuetotext+"']")).click();
}

Html code is :

span class="nodeTag">div id="ext-gen1978" class="x-layer x-combo-list " style="position: absolute; z-index: 9010; visibility: hidden; left: -10000px; top: -10000px; width: 178px; height: 69px; font-size: 12px;">
span class="nodeTag">div id="ext-gen1979" class="x-combo-list-inner" style="width: 178px; height: 69px;">
span class="nodeTag">div class="x-combo-list-item x-combo-selected">General</div>
span class="nodeTag">div class="x-combo-list-item">Instrumental</div>
span class="nodeTag">div class="x-combo-list-item">Microbial</div>
</div>
</div>
span class="nodeTag">div id="ext-gen1981" class="x-layer x-combo-list " style="position: absolute; z-index: 9010; visibility: hidden; left: -10000px; top: -10000px; width: 178px; height: 69px; font-size: 12px;">
span class="nodeTag">div id="ext-gen1982" class="x-combo-list-inner" style="width: 178px; height: 69px;">
span class="nodeTag">div class="x-combo-list-item">General</div>
span class="nodeTag">div class="x-combo-list-item x-combo-selected">Instrumental</div>
span class="nodeTag">div class="x-combo-list-item">Microbial</div>
</div>
</div>

Views: 372

Reply to This

Replies to This Discussion

So Selenium recognize the elements from left to right. So drop downs you have must consist of same values under it. So try out putting the brackets around the xpath and give the index of the drop down.
e.g.
driver.findElement(By.xpath( "(//x-path).[2]")).click(); (for the second drop down)

Try to get the values from second drop down. If it works we can try it out for the next drop down.

this should work.

Use:
WebElement element=driver. findelement by tagname.
After that :
Again from that
find:
List=element.find elements
Then
Get the size that is the total no. Of items in that list.
Use iterator
For i=0 ;I<=List.size();I++{
Then
Find to identify your locator using
Contains text value
}
If the value matches then select and get out of the loop and do the next operation
Hope this should work.
Thanks
Shivakumar from
Did you get a Solution,or my Solution works, lemme know.
Regards
Shivakumar

You have use

List<WebELements> e = driver.findelementByclass("x-combo-list-item");

foreach(Weblement e1:e){

if (e.text ="Instrumental"){

e.click();}

}

Hi,

You can simply use the index value of the respective text to be selected in the xpath (if the order of dropdown remains same). E.g. */span[1], */span[2]
And then try to click the element.

This is a common method used by experts of automation testing company.

It should work.

Thanks,
Anand

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2020   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service