简体   繁体   中英

Select item from drop down menu in C# using Selenium in web assembly - doesn't work

I am working with some automated tests and I am using Selenium Web driver with that. I have wrote a script till now that can find the class but cannot select either one of the items in the drop down.

This is my script till now:

driver.FindElement(By.Id("loginOK")).Click();
Thread.Sleep(3000);
driver.FindElement(By.XPath("//*[@id = \"content\"]/div[3]/div[2]/div[1]/a[1]")).Click();
Thread.Sleep(3000);
driver.FindElement(By.XPath("//*[@id= \"sec1272\"]/table/tbody/tr[2]/td[2]/div/img")).Click();
Thread.Sleep(3000);
driver.FindElement(By.ClassName("fm - s fm - off fm - focused"));

and I want to select one of the items below:

    <tbody>
    <tr class="row" oid="12" height="24"><td class="ln">Bujqesi, Zhvillim rural, Pyjet dhe kullotat, Natyra dhe Biodiversiteti</td></tr>
    <tr class="row-selected" oid="13" height="24"><td class="ln">Burime Njerezore</td></tr>
    <tr class="row" oid="9" height="24"><td class="ln">Administrimi dhe menaxhimi i institucioneve te arsimit parauniversitar</td></tr>
    <tr class="row" oid="14" height="24"><td class="ln">Ceshtje ligjore/Asete</td></tr>
    <tr class="row" oid="15" height="24"><td class="ln">Emergjencat Civile/Mbrojtja nga Zjarri</td></tr>
    <tr class="row" oid="10" height="24"><td class="ln">Hapesire Publike/Mjedis</td></tr>
    <tr class="row" oid="2" height="24"><td class="ln">Kerkesa/Ankesa te pergjithshme</td></tr>
    </tbody>

Many thanks in advance :)

So, how does one actually select the items in the drop down? I've never seen a table used as a dropdown. Are the events attached to the "tr" table row elements, or to the "td" cell elements?

Are you saying that your script provided finds the td element by the class name ("ln"), but what you really need is to select the parent element, which is the table row element?

Are you trying to select a specific row, or any of them will do? Let's assume you specifically want an option containing "Biodiversiteti".

using System.Linq;
using System.Collections.Generic;

List<IWebElement> options = driver.FindElements(By.TagName("tr")).ToList();
IWebElement selectOption = options.Find(x => x.FindElement(By.TagName("td")).Text.Contains("Biodiversiteti"));
selectOption.Click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM