简体   繁体   中英

Selenium c#: How to get the Id attribute?

I would like to get the id from the following code:

图片

This id is generating dynamically, can be different each times.

The Xpath looks as below:

//*[@id="chart_9"]

The Xpath from one line above is following:

//*[@id="TransientResponse_tab"]/div[2]/div/div[2]

The problem is that I can't get the id - I have tried in different ways, eg:

driver.FindElement(By.ClassName("chartContainer")).GetAttribute("id");

It also doesn't work.

Can you give some tips how I can struggle with it?

Try this -

String s1 = driver.FindElement(By.CssSelector("div.chartContainer")).GetAttribute("id");

Hope this helps.

您可以通过更多方式获得它:

String text = driver.FindElement(By.Xpath("//div[class='chartContainer']")).GetAttribute("id");

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