0

I am trying to click on a button in some website using c# code and it's code from the inspector:

<td colspan="1" rowspan="1" align="left"><table class="t10Button" cellspacing="0" cellpadding="0" border="0" summary=""> <tbody><tr> <td class="t10L"><a href="javascript:apex.submit('LOGIN');"><img src="/i/themes/theme_10_ar/button_left.gif" alt="" width="4" height="24"></a></td> <td class="t10C"><a href="javascript:apex.submit('LOGIN');">Sign-in</a></td> <td class="t10R"><a href="javascript:apex.submit('LOGIN');"><img src="/i/themes/theme_10_ar/button_right.gif" width="4" height="24" alt=""></a></td> </tr> </tbody></table></td> 

My code looks something like this:

webBrowser1.Document.GetElementById("t10C").InvokeMember("submit"); 

But I have failed: Nothing happens when the code gets executed.

5
  • 3
    "I have failed" is not a sufficient error description. Commented Dec 14, 2017 at 16:50
  • 1
    I don't see any element with the id of "javascript:apex.submit('LOGIN');" Commented Dec 14, 2017 at 16:51
  • actually nothing happens when the code get executed. Commented Dec 14, 2017 at 16:51
  • yes there is not, so how to retrieve the element without an id? Commented Dec 14, 2017 at 16:52
  • 1
    Maybe try InvokeScript directly? msdn.microsoft.com/en-us/library/… Commented Dec 14, 2017 at 17:05

1 Answer 1

1
for (int i = 0; i < webBrowser1.Document.Links.Count; i++) if (webBrowser1.Document.Links[i].GetAttribute("href") == "javascript:apex.submit('LOGIN');") { webBrowser1.Document.Links[i].InvokeMember("Click"); } 

It will click on a link if it's url is javascript:apex.submit('LOGIN');.

Sign up to request clarification or add additional context in comments.

6 Comments

yes that worked for me, thanks alot, but what about a table element? like this: <td><a href="f?p=134:14:1168788664179308::NO:::"><img src="/i/menu/instructor_wbg_64x64.png" border="0"></a><br><a href="f?p=134:14:1168788664179308::NO:::"><div style="width:150px">‎Student Information System</div></a></td> I want to click on it, but the same method doesn't work, so what is the problem?
@O-BL Please tell me what you have made so far and what are you trying to do? You want to click on the link again?
Actually I am trying to get the courses that my university site offer to let me pick some of them easily for the next semester and here is my code so far:
webBrowser1.Document.GetElementById("P101_USERNAME").InnerText = "myID"; webBrowser1.Document.GetElementById("P101_PASSWORD").InnerText = "myPass"; foreach (HtmlElement Link in webBrowser1.Document.Links) { if (Link.GetAttribute("href") == "javascript:apex.submit('LOGIN');") { Link.InvokeMember("Click"); break; } }
after I have loged-in I want to enter another link that is presented in the java-script above.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.