You are viewing our Forum Archives. To view or take place in current topics click here.

C# help getting IDs.Posted:

E60
  • Christmas!
Status: Offline
Joined: Apr 24, 20126 Year Member
Posts: 3,560
Reputation Power: 311
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
  • 1K Rainmaker
Status: Offline
Joined: Oct 09, 20107 Year Member
Posts: 2,320
Reputation Power: 104
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
  • Wizard
Status: Offline
Joined: Dec 25, 20098 Year Member
Posts: 2,312
Reputation Power: 530
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.