SimpleBrowserDotNet/SimpleBrowser

Finding Specifc Child Element of a "div" elment without class Name Or ID

EyassShahoud opened this issue · 4 comments

So am able to recognize and find an element with Its ClassName, but I need the specific child of that Element.
But the Children of this Element have all the same class Name, so I can't Select based on the class name.
Untitled

as the Image showing, I can find the Element inside the yellow box but not the Child of that Element which the Arrow pointing to.
is there a way to select that element ?

Luckily, the class name is not the only way to find an element. There are a few things to try. Without the URL you are working with, I can't test for myself to know whether or if any of the following will work:

Option 1: public HtmlResult Find(string tagName, object elementAttributes)
Rather than selecting by class, select using the data-star attribute where data-star = "5". This may not work because data-star has a dash ('-') in it.

Option 2: public HtmlResult Select(string query)
Rather than finding elements, search for them using a jQuery selector. browser.Select("data-star='5')" should work.

Option 3: public HtmlResult FindAll(string tagName)
Worst case scenario, you could find all divs, then loop through them looking for the one you need. This is the worst way to go, but if all else fails, you may have to do this to get it to work.

It is worth mentioning that while SimpleBrowser can do parent-child and ancestor relationships, it's best to just get the one item you're looking for. I don't know what is inside of the div with the yellow arrow, but if it is more than text that you're trying to get, you are probably going to want to search for the item inside of the div without regard to the div being the parent element.

Let me know how that works.

Kevin

@EyassShahoud Did you get this working? Can this issue be resolved?

@kevingy you know how can i find by href?

@Kiriakos41 Use the Browser.Find method that takes an attribute name and attribute value:
public HtmlResult Find(ElementType elementType, string attributeName, string attributeValue)

For example:
HtmlResult result = browser.Find(ElementType.Anchor, "href", "http://www.example.com/your/href");