C# 找不到具有动态id的元素
我正在尝试查找元素,但id每次都会更改 这是相同的HTML代码:C# 找不到具有动态id的元素,c#,xpath,selenium-webdriver,C#,Xpath,Selenium Webdriver,我正在尝试查找元素,但id每次都会更改 这是相同的HTML代码: <a id="A7632AF8-BE67-4AEA-9621-437B54235111" target="K2MenuSystemMainFrame" title="New Second Level Menu Item" href="https://thehubtest.cargill.com/Runtime/Runtime/Form/TheHub.TemplateDistribution/" onclick="desele
<a id="A7632AF8-BE67-4AEA-9621-437B54235111" target="K2MenuSystemMainFrame" title="New Second Level Menu Item" href="https://thehubtest.cargill.com/Runtime/Runtime/Form/TheHub.TemplateDistribution/" onclick="desele"/>
在您的情况下,可以使用以下xpath:
Xpath=//a[contains(@href,'https://thehubtest.cargill.com/Runtime/Runtime/Form/TheHub.TemplateDistribution/')]
希望它能帮助您。在您的情况下,您可以使用以下xpath:
Xpath=//a[contains(@href,'https://thehubtest.cargill.com/Runtime/Runtime/Form/TheHub.TemplateDistribution/')]
希望它能帮助你。试试这个
Xpath=//a[包含(@title,'New Second Level Menu Item')]
希望它能帮助你。试试这个
Xpath=//a[包含(@title,'New Second Level Menu Item')]
希望它能帮助您。也许您可以借助字符串匹配编写css定位器 ^=匹配前缀 $=匹配后缀 *=匹配子字符串
也许你可以在字符串匹配的帮助下编写css定位器 ^=匹配前缀 $=匹配后缀 *=匹配子字符串
到目前为止你试过什么?您是在询问具有动态ID的元素,还是根本找不到该元素或出现任何错误?我找不到该元素您能否更新问题中的代码您是如何尝试Thread.Sleep(6000)的;driver.FindElement(By.Id(“A5D45A48-1327-4782-835E-5825231A6A37”)。单击();睡眠(10000);FindElement(By.XPath(“./*[包含(@title,'New Second Level Menu Item')]))))。单击();试试这个xpath,如果有任何问题,请告诉我[@title='New Second Level Menu Item']到目前为止您尝试了什么?您是在询问具有动态ID的元素,还是根本找不到该元素或出现任何错误?我找不到该元素您能否更新问题中的代码您是如何尝试Thread.Sleep(6000)的;driver.FindElement(By.Id(“A5D45A48-1327-4782-835E-5825231A6A37”)。单击();睡眠(10000);FindElement(By.XPath(“./*[包含(@title,'New Second Level Menu Item')]))))。单击();请尝试此xpath,如果有任何问题,请告诉我[@title='New Second Level Menu Item']OpenQA.Selenium.InvalidSelectorException:无法找到带有xpath表达式的元素。//*[包含(@title,'New Second Level Menu Item')]由于以下错误:错误:错误标记:“新建二级菜单项”OpenQA.Selenium.InvalidSelectorException:无法找到具有xpath表达式的元素。//*[包含(@title,'New Second Level Menu Item')],因为以下错误:错误标记:“新建二级菜单项”
css=a[target$='MainFrame']
or
css=a[title$='Level Menu Item']
css=a[target*='SystemMain']