0

I have selected the drop-down now i want to verify the selected drop down is correct using Assert

I have noticed that the selected item has attribute "selected"

var ftpTransDropdown = Driver.FindElement(By.Id("FtpTransmittalMethods")); var selectFtpTransDrpdwn = new SelectElement(ftpTransDropdown); selectFtpTransDrpdwn.SelectByText("NIHMS-PubMed Central Deposit (manuscript-dtd)");<code>enter image description here</code>

Assert.AreEqual("NIHMS-PubMed Central Deposit (manuscript-dtd)", "
");

I have attached HTML screenshot

1 Answer 1

1

Rather than AreEqual(), I'd probably see if you can use .IsTrue() after you've selected the option.

Assert.IsTrue(Driver.FindElement(By.Id("FtpTransmittalMethods")).FindElement(By.CssSelector("option[selected='selected']")).Selected);

or

Assert.IsTrue(ftpTransDropdown.FindElement(By.CssSelector("option[selected='selected']")).Selected);

Doing it this way, you'll still be looking at the element, but, you'll be asserting that the option with the selected attribute with a value of selected is actually the one selected in the SelectElement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.