<div class="left">
<select id="hidebox" class="ays-ignore" size="8">
<ul><option value="103249">260 - OMAHA 30TH ST</option></ul>
<ul><option value="103266">540 - UNION CITY</option></ul>
<ul><option value="3">800 - BETHLEHEM</option></ul>
<ul><option value="103271">430 - DALLAS SOUTH</option></ul>
<ul><option value="103270">410 - DALLAS</option></ul>
<ul><option value="100966">530 - TRACY</option></ul>
<ul><option value="103272">420 - FORT WORTH</option></ul>
<ul><option value="97224">820 - QUAKERTOWN</option></ul>
<ul><option value="103324">520 - SACRAMENTO</option></ul>
</select>
</div>
Hello, I'm trying click on an element based on the label "820 - QUAKERTOWN" and my approach is either incorrect or im missing something cause when i step thru, i see the entire list being returned but the required value is not clicked. The xpath is correct and appears to return the correct list of records, but the click is not being applied. My apologies if I use the wrong verbiage im new to Selenium and Java. I excluded the driver and get() website code, those lines were not revelant to my question. Please suggest other ideas if im using the wrong approach. I somewhat hit the wall.
My expectation is that the row can be clicked using the label text such as "800 - BETHLEHEM" or any other from list. I did try the unique xpath approach and it worked, but my test fails when I run it against other environments where the option value is different.
Thank you for any help y'all can provide. Example from a successful clicked when I used a unique xpath which I rather not used because of the environment reason.
package com.usc.uscspace.test.customer;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.testng.annotations.Test;
import java.util.List;
public class CreateTest extends AbstractTestClass {
final static String legacyWarehouse = "800 - BETHLEHEM";
@Test
public void createCustomerTest() {
List<WebElement> pushWhseList = driver.findElements(By.xpath(".//*[@id='hidebox']"));
int total_node = pushWhseList.size();
for (int i = 0; i < total_node; i++) {
String list = pushWhseList.get(i).getText();
if (list.contains(legacyWarehouse)) {
pushWhseList.get(i).click();
break;
}
}
}
}