Reputation: 11
I am getting element not visible exception in carrier drop-down list. I tried implicit wait, explicit wait, and all id, class, XPath, CSS selector way to find the element. Please help me to get to get the right XPath. I have "element not visible" exception error message at select a carrier drop-down list. Thank you .
<select class="form-control error" id="smsCarrier" name="smsCarrier" required="" data-required-message="Carrier is required." aria-required="true" aria-invalid="false">
<option value="-1">Select a Carrier</option>
<option value="@message.alltel.com">Alltel</option>
<option value="@txt.att.net">AT&T</option>
<option value="@myboostmobile.com">Boost Mobile</option>
<option value="@sms.cricketwireless.net">Cricket Wireless</option>
<option value="@msg.fi.google.com">Project Fi</option>
<option value="@text.republicwireless.com">Republic Wireless</option>
<option value="@messaging.sprintpcs.com">Sprint</option>
<option value="@tmomail.net">T-Mobile</option>
<option value="@email.uscc.net">US Cellular</option>
<select class="form-control error" id="smsCarrier" name="smsCarrier" required="" data-required-message="Carrier is required." aria-required="true" aria-invalid="false">
<option value="-1">Select a Carrier</option>
<option value="@message.alltel.com">Alltel</option>
<option value="@txt.att.net">AT&T</option>
<option value="@myboostmobile.com">Boost Mobile</option>
<option value="@sms.cricketwireless.net">Cricket Wireless</option>
<option value="@msg.fi.google.com">Project Fi</option>
<option value="@text.republicwireless.com">Republic Wireless</option>
<option value="@messaging.sprintpcs.com">Sprint</option>
<option value="@tmomail.net">T-Mobile</option>
<option value="@email.uscc.net">US Cellular</option>
<option value="@vtext.com">Verizon</option>
<option value="@vmobl.com">Virgin Mobile</option>
</select>
I used Fluent wait.
public void ContinueWhenReady(By locator, int timeout)
{
for (int i = 0; i < 2; i++)
{
try
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeout));
IWebElement element = wait.Until(ExpectedConditions.ElementToBeClickable(locator));
break;
}
catch (Exception e)
{
}
}
}
//PhoneNumberDetails details = table.CreateInstance<PhoneNumberDetails>();
ContinueWhenReady(By.CssSelector("#smsCarrier"), 50);
var SelectaCarrierDropDown = driver.FindElement(By.CssSelector("#smsCarrier"));
SelectaCarrierDropDown.Click();
var selectaCarrierElement = new SelectElement(SelectaCarrierDropDown);
//selectaCarrierElement.SelectByText(details.SelectaCarrier);
selectaCarrierElement.SelectByValue("@myboostmobile.com");
Upvotes: 0
Views: 1328
Reputation: 29372
In JAVA you can do something like :
WebDriverWait wait = new WebDriverWait(driver, 10);
Select dropdown = new Select(wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.id("smsCarrier")))));
dropdown.selectByVisibleText("Cricket Wireless");
Upvotes: 1
Reputation: 16
As others have mentioned your question isn't really detailed enough to know your exact problem, but there are a couple common ones when working with dropdowns in Selenium that I can point out.
First, you need to make sure the select has actually loaded on the page before you try to find it. So you may need to use a WebDriverWait to do that. Example:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("smsCarrier")));
Then you can try to locate the dropdown and store it in a WebElement:
WebElement carrierDropdown = driver.findElement(By.id("smsCarrier"));
The trick is, to work with dropdowns you need to then wrap that WebElement in a Select object:
Select carrierSelect = new Select(carrierDropdown);
From there you can use methods on that Select object to manipulate it, such as selecting an option from the dropdown. Example:
carrierSelect.selectByVisibleText("Boost Mobile");
or
carrierSelect.selectByValue("@myboostmobile.com");
Hope that helps!
Upvotes: 0