1
<ul class="options"> 
<li data-raw-value="smt-b1bbdd96-f135-48ae-8744-e920942dd7a3" class="selected" data-sys-status="running">3.   LIELA LEGAL SISTĒMA ( EN - LV )</li>

I want to select the specific item with the attribute value in the data-war-value attribute. So far have just made the way to the section but stopped at the selection.

driver.Navigate().GoToUrl(baseUrl + TextTranslate);
new SelectElement(driver.FindElement(By.ClassName("options"))).SelectByText(sysID);

When I run the test with this kind of code I get this error :

Test Outcome: Failed Test Duration: 0:00:08,7050235 Result StackTrace: at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse) at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByClassName(String className) at OpenQA.Selenium.By.<>c__DisplayClass12.b__10(ISearchContext context) at OpenQA.Selenium.By.FindElement(ISearchContext context) at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) at FirstUnitTest.LetsMT_Tests.TranslateText() in C:\Users\edgars.karkis.TILDE\Documents\Visual Studio 2015\Projects\FirstUnitTest\FirstUnitTest\LetsMT_Tests.cs:line 59 Result Message: Test method FirstUnitTest.LetsMT_Tests.TranslateText threw exception: OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"class name","selector":"options"} (Session info: chrome=46.0.2490.71)
(Driver info: chromedriver=2.20.353145 (343b531d31eeb933ec778dbcf7081628a1396067),platform=Windows NT 10.0 x86_64)

I have tried to select/ click the item, but the error repeats, that the element could not me found.

driver.Navigate().GoToUrl(baseUrl + TextTranslate);
driver.FindElement(By.ClassName("translateSystemContainer")).Click();
new SelectElement(driver.FindElement(By.ClassName("options"))).SelectByText(sysID);
  • have you tried clicking on the drop down first and then using the code for selection? – demouser123 Oct 16 '15 at 15:30
  • Yes i have tried many variants to get somekinde of response. The error still thesame , that the element could not be found the test fails. driver.Navigate().GoToUrl(baseUrl + TextTranslate); driver.FindElement(By.ClassName("translateSystemContainer")).Click(); new SelectElement(driver.FindElement(By.ClassName("options"))).SelectByText(sysID); – Edgars Karķis Oct 19 '15 at 7:54
1
new SelectElement(driver.FindElement(By.ClassName("options"))).SelectByText(sysID);

Here you are trying to find the element where class="options", which is a <ul>. You can't 'select' a UL. You can select if it's a list.

Also, check this out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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