Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simulate click which fires javascript

Status
Not open for further replies.

Keneda88

Programmer
Oct 30, 2007
18
US
I am having trouble getting a button on a web page to click. I am able to get the element and have tried using invokemember but it didnt not work. All i want to do i simulate a click on a button that fires off a javascript to the next page.
when you put the curser over the button javascript appears in the lower corner of the browser. it reads javascript:gotopage(2);
if it was going to page 3 the 2 would be replaced by 3 ect
thanks
 
Why do you need to submit a click? you can just navigate to the next page (Javascript):
Code:
Response.Redirect("../page1.asp")
or else just call the sub that is called when the button is clicked.
Code:
var blnFlag = mySubmit()
if (blnFlag)
  Response.Redirect("../page2.asp")
end if


-The answer to your problem may not be the answer to your question.
 
i have already tried both of those possibilities. neither of them bring up the next page...
 
Well, then post up the existing block that you are having problems with, because I pulled that code directly off of a production page.

-The answer to your problem may not be the answer to your question.
 
I dunno if this will help, but in the gottopage function put this
Code:
javascript:gotopage(2);
put this
Code:
function gotopage(pageIndex)
{
window.location.href='[URL unfurl="true"]www.mypage'[/URL] + pageIndex + '.com';
}
 
im not sure if i am doing it right. Here is exactly what i am doing and some of the code. I want to save a link on an html weppage that has javascript behind it then i want to invoke (somehow start that javascript) so it will take me to the next page. The url's seem to be random so there is no way to navigate to the next page without clicking it. the page is open in webbrowser
i have declared linkElement as an htmlelement
linkElement = WebBrowser.Document.GetElementById("Name of link elemnt)
then i have tried using
linkelement.invokemember("click")
(and also submit and onclick as the method)

another approach ive tried is
WebBrowser.Document.InvokeScript("gotopage(index)")
where gotopage() was the function name of the javascript and index would grow as the the page number

Response.Redirect("../page1.asp")
i tried that but im not sure if i put the right thing in quote. the javascript funtion im trying to call is below

function GotoPage(pageNumber)

theForm.page.value = pageNumber;
theForm.action = "Browse.aspx?MyToken=633298554866367134";
theForm.submit();
return true;

thanks for all the help
 
have you verified that your submit function is returning true?

I am not sure what you have going on with the frm.page.value.

You may want to step back, create a couple empty test pages that mimic what your environment and try a couple things along the lines of completely gutting your submit function and put your redirect or an alert in there to ensure you are getting there.


Side question, are you creating the javascript in the design code file, or in the code behind as some form of Document.Write()?

-The answer to your problem may not be the answer to your question.
 
im not sure what you mean by that. and no my program does not include any javascript. I am very new to vb.net and dont know javascript
 
Here is another example to execute javascript from a page:

Webbrowser.Navigate("javascript:document.links[6].click()")

or

Have you tried:

Webbrwoser.Document.InvokeScript("GotoPage")

Let me know. Somehow I have become pretty decent at automating websites and scraping data...ha ha.
 
WebBrowser.Navigate("javascript:document.links[6].click()")
this seems to work however im not sure what to enter instead of 6
is there a way i can talk to you (arznrchrd) on aim or something?
 
Bring up the page of interest and test different link numbers. There is a way to get the number of links, but if it is not a page with a lot of javascript, just test starting at 0. Use try/catch blocks though. Can't recall how to get at the link numbers in code. I am not on AIM.
 
well the problem is for every page it is a different link number
 
There is a way to get the link number. Will have to look at some old code when I have time.
 
well i think the problem i have to pass an object to the javascript. look at the code above... i just dont know how to get that object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top