Selenium C# - verifying the drop down was selected item



  • 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



  • 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.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2