简体   繁体   中英

Xpath selenium finding elements

How can I get class="aaa34" using selenium and xpath?

client.Navigate().GoToUrl("*insert your URL here*");
IWEBELEMENT firstDiv =  client.FindElement(By.XPath("//div[contains(@class,'__next')]"));

IWEBELEMENT secondDiv = firstDiv.FindElements(By.ClassName("jss1"));

This should do it. First I'm getting the parent div enclosing the div you want. That way I can get all the elements inside it, then filter what I want from it using the second IWEBELEMENT variable. Let me know if it doesn't work. There are other methods of selecting the div that could work. :)

if your class is unique and doesn't change with page loading, try following. I can't test it at my end though.

chrome.find_elements_by_class_name("jss1945")

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