簡體   English   中英

我想在下拉列表中選擇一個項目,但每次運行時下拉列表的 id 都會改變

[英]I want to select an item in a dropdown list but the id of the dropdown list change with every run

我想在下拉列表中選擇一個項目,但每次運行時下拉列表的 id 都會發生變化。 這是元素代碼: <ul unselectable="on" class="k-list k-reset" tabindex="-1" aria-hidden="true" id="TableName_c2937ec1-50e5-4df6-b2e1-8a9c0a2b3f9f_listbox" aria-live="polite" data-role="staticlist" role="listbox"><li tabindex="-1" role="option" unselectable="on" class="k-item" aria-selected="false" data-offset-index="0">CaseCmsCustomerDto</li>

我的代碼

IWebElement fltTableNm = _driver.FindElement(By.XPath("/html/body/div[4]/div/div/div/div[1]/div/div/div[1]/div/div[3]/table/tbody/tr[2]/td[2]/fieldset[2]/div[1]/div[1]/div/span/span"));
            fltTableNm.Click();
            Thread.Sleep(1000);
            IWebElement slctfltTableNm = _driver.FindElement(By.XPath("//id=[starts-with(.,'TableName')]/li[1]"));
            slctfltTableNm.Click();

這個xpath怎么樣? 你的想法是對的,id 是動態的,但包含一些足夠獨特的東西。 你的 xpath 錯過了 //ul 並以這樣的方式開始:

IWebElement slctfltTableNm = _driver.FindElement(By.XPath("//ul[starts-with(@id,'TableName')]/li[1]")); 

或者 By.XPath("//ul[@class='k-list k-reset']/li[1]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM