Selenium to click on an app name in a filter tool

后端 未结 1 1544
孤街浪徒
孤街浪徒 2021-01-27 14:35

I have another requirement like this in my c# selenium application. Since there are so many content in my webpage table, it will be quite nice to sort it based on the app name.

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-27 15:12

    First of all, HTML code is far more concise than showing the business model in order to illustrate your problem. Please post it if possible.

    Now for this question, what you are trying to do exactly? I can only make comments based on the code you provided.

    // are you sure want to get all spans? This will get you lots more unrelated ones
    // please try use xpath or css selector to only get the ones related
    IList spanList = driver.FindElements(By.TagName("span"));
    
    // now you want loop through each of them, check if text == App4 as an example
    foreach (IWebElement span in spanList) {
        if (span.Text == "App4") {
            // click the span with text App4
            span.Click(); // not sure what you want to click here, please clarify
        }
    }
    
    // version using Linq
    // spanList.First(span => span.Text == "App4").Click();
    

    0 讨论(0)
提交回复
热议问题