我在运营商下拉列表中遇到了元素不可见的异常。我尝试了隐式等待,显式等待以及所有id,class,XPath,CSS选择器方式来查找元素。
请帮助我获得正确的XPath。我有“元素不可见”异常错误消息。
<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>
我用过流利的等待。
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");