Мне нужна помощь, пожалуйста ... У меня проблемы с оператором ELSE, код выполняет все, что находится в скобках IF, но никогда не достигает скобок ELSE.Он работает без проблем с Chrome, но каждый раз терпит неудачу с IE.Это мой код:
IWait<IWebDriver> wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(3.00));
IList<IWebElement> boxList = _driver.FindElements(By.CssSelector("ListBox option"));
bool textExists = false;
foreach (var option in boxList)
{
if (option.Text.Equals("TEST"))
{
textExists = true;
break;
}
}
if (!textExists)
{
_driver.FindElement(By.Id("AddButton")).Click();
var newRecordInfo = table.CreateSet<FeatureInfo>();
foreach (var recordData in newRecordInfo)
{
_driver.FindElement(By.Id("DescTextBox")).SendKeys(recordData._discription);
_driver.FindElement(By.Id("PaTextBox")).SendKeys(recordData._score);
new SelectElement(_driver.FindElement(By.Id("DropDown"))).SelectByValue("1");
_driver.FindElement(By.Id("SaveButton")).Click();
}
}
else
{
SelectElement Select = new SelectElement(_driver.FindElement(By.Id("ListBox")));
Select.SelectByText("TEST");
_driver.FindElement(By.Id("DeleteButton")).Click();
IAlert alert = _driver.SwitchTo().Alert();
alert.Accept();
//IJavaScriptExecutor js = (IJavaScriptExecutor)_driver;
//js.ExecuteScript("window.confirm = function(msg) { return true; }");
Thread.Sleep(1000);
}
Вот HTML:
IE
<div class="section-container">
<div class="section">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width:52%" valign="top">
<h5 class="section-label">Active Values</h5>
<div class="section">
<select size="10" name="DescTextBox" id="DescTextBox" onclick="ListBox_Click()" style="width:98%;display:block;margin-bottom:10px">
<option value="14" UseCount="0" PassingScore="50" FirearmType="1">123ABC</option>
<option value="10" UseCount="0" PassingScore="170" FirearmType="2">BRTP</option>
<option value="9" UseCount="0" PassingScore="0" FirearmType="1">CORE TRAINING ELEMENTS</option>
<option value="12" UseCount="0" PassingScore="0" FirearmType="1">FAM (T&E PISTOL)</option>
<option value="5" UseCount="559" PassingScore="0" FirearmType="2">FAM ONLY (RIFLE)</option>
<option value="1" UseCount="31" PassingScore="225" FirearmType="1">FLETC PPC (NON-CITP)</option>
<option value="2" UseCount="4001" PassingScore="225" FirearmType="1">HHS-OIG PQC</option>
<option value="3" UseCount="603" PassingScore="240" FirearmType="2">HHS-OIG RQC</option>
<option value="6" UseCount="5" PassingScore="0" FirearmType="1">OTHER FEDERAL AGENCIES-PISTOL</option>
<option value="7" UseCount="2" PassingScore="0" FirearmType="2">OTHER FEDERAL AGENCIES-RIFLE</option>
<option value="11" UseCount="0" PassingScore="0" FirearmType="2">RCTP</option>
<option value="16" UseCount="0" PassingScore="50" FirearmType="1">TEST</option>
<option value="15" UseCount="0" PassingScore="50" FirearmType="1">TEXT_DELETE</option>
</select>
CHOME
<div class="section-container">
<div class="section">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="width:52%" valign="top">
<h5 class="section-label">Active Values</h5>
<div class="section">
<select size="10" name="DescTextBox" id="DescTextBox" onclick="ListBox_Click()" style="width:98%;display:block;margin-bottom:10px">
<option value="14" UseCount="0" PassingScore="50" FirearmType="1">123ABC</option>
<option value="10" UseCount="0" PassingScore="170" FirearmType="2">TRAINING</option>
<option value="9" UseCount="0" PassingScore="0" FirearmType="1">TRAINING TWO</option>
<option value="12" UseCount="0" PassingScore="0" FirearmType="1">TRAINING THREE</option>
<option value="5" UseCount="559" PassingScore="0" FirearmType="2">TRAINING FOUR</option>
<option value="1" UseCount="31" PassingScore="225" FirearmType="1">TRAINING FIVE</option>
<option value="16" UseCount="0" PassingScore="50" FirearmType="1">TEST</option>
<option value="15" UseCount="0" PassingScore="50" FirearmType="1">TEXT_DELETE</option>
Обновлен пост, чтобы добавить HTML для IE и Chrome