You are viewing our Forum Archives. To view or take place in current topics click here.
C# help getting IDs.
Posted:

C# help getting IDs.Posted:

Speedom
  • V5 Launch
Status: Offline
Joined: Apr 24, 201212Year Member
Posts: 3,645
Reputation Power: 316
Status: Offline
Joined: Apr 24, 201212Year Member
Posts: 3,645
Reputation Power: 316
So I'm new to coding, started yesterday. Just doing it for some fun and to create some helpful programs.

Nearly finished with a program I've been working on for the past few hours but can't work out how to get inspect element IDs from certain websites.

Basically, I'm trying to code a button to click a something in the WebBrowser, looked it up online and can't work it out.

This is the Facebook inspect element:

[ Register or Signin to view external links. ]

as you can see it has the ID but this is the button I'm trying to link.

[ Register or Signin to view external links. ]

as you can see it has no ID.

I was using the code: webBrowser1.Document.GetElementById("").InvokeMember("click");

Can I link the button any other way?

Sorry for my terrible explanation.
#2. Posted:
Xaldin
  • TTG Addict
Status: Offline
Joined: Oct 09, 201013Year Member
Posts: 2,358
Reputation Power: 106
Status: Offline
Joined: Oct 09, 201013Year Member
Posts: 2,358
Reputation Power: 106
Might be a good place to start,

[ Register or Signin to view external links. ]

element doesnt have an ID so youll have to get it by class which is more complex is C#. Im not familiar with this but doing some research it seems like youll have to get all the <input> tags and then search through them for the class name like the example in the above link.
#3. Posted:
tortuga
  • Fairy Master
Status: Offline
Joined: Dec 25, 200914Year Member
Posts: 2,314
Reputation Power: 1686
Status: Offline
Joined: Dec 25, 200914Year Member
Posts: 2,314
Reputation Power: 1686
If the DOM element you want to select does not have an id, you have to figure out another way you can uniquely select it.

Maybe one of the button's parent elements has an id, and there are no other buttons within that parent. In this case the CSS selector to uniquely select your button can be #parent-id input.

Or, maybe a combination of classes can uniquely select your element.

Or, maybe you can select by looking at the value attribute of your element, something like input[value="Check Availability"].

I don't know the .NET API for DOM interaction, but if it's worth its salt, it should support selecting elements via their appropriate CSS selector.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.