Kashgari Posted September 23, 2009 Posted September 23, 2009 Hi, I am new here and learning Autoit, I am excited to discover the capabilities of it. I am testing a simple script but having hard time . please help. This is the script I am testing : #Include <FF.au3> _FFConnect() If _FFIsConnected() Then _FFOpenUrl("http://www.example.com/news/811") Sleep(6000) _FFClick(".forms[2].elements[0]") _FFLoadWait() EndIf I want to submit a form in Firefox, selecting the first element, there are 3 elements, only second element is working when I tried. This one is working _FFClick(".forms[2].elements[1]") BUT these two are not producing any result. _FFClick(".forms[2].elements[0]"),or _FFClick(".forms[2].elements[2]") This is the source code for the webpage. <form action="http://www.example.com/search" class="search-form" method="get"> <fieldset> <ul> <li><label for="header_query" class="alt">Search</label> <input class="textfield" id="header_query" name="query" size="30" type="text" /></li> <li class="submit"><input src="/images/buttons/search.png" type="image" /></li> </ul> </fieldset> </form> <form action="http://www.example.com/vote/for/811" class="vote-for" method="post"> <input type="hidden" name="collection" value="1" /> <button type="submit" class="submit" title="Vote for"><span class="alt">Vote for</span></button> </form> <form action="http://www.example.com/vote/against/811" class="vote-against" method="post"> <input type="hidden" name="collection" value="1" /> <button type="submit" class="submit" title="Vote against"><span class="alt">Vote against</span></button> </form> Thank you very much.
Stilgar Posted September 23, 2009 Posted September 23, 2009 (edited) Hello, at first, it's simpler to use just _FFFormSubmit instead of clicking the elements. In every _FFClick(...) you are using the third form (.forms[2]) on this page - this one: <form action="http://www.example.com/vote/against/811" class="vote-against" method="post"> <input type="hidden" name="collection" value="1" /> <button type="submit" class="submit" title="Vote against"><span class="alt">Vote against</span></button> </form> The command: _FFClick(".forms[2].elements[0]") clicks there on the <input type="hidden" ... and your click on the third element: _FFClick(".forms[2].elements[2]") should throw an error, because there are only 2 elements in this form. So it's correct that only this one works: _FFClick(".forms[2].elements[1]") If wanna submit the first form: _FFFormSubmit() OR _FFClick(".forms[0].elements[2]") - elements[2] because the fieldset is an element, too the second: _FFFormSubmit(1) OR _FFClick(".forms[1].elements[1]") the third form: _FFFormSubmit(2) OR _FFClick(".forms[2].elements[1]") [EDIT] If you not sure which index a form have, you can do something like this: $sObj = _FFXPath("//form[@class='vote-against']//button[@type='submit']", "", 9) _FFClick($sObj) ; short: _FFClick( _FFXPath("//form[@class='vote-against']//button[@type='submit']", "", 9) ) or you can use the "FF-Page-Analyzer": http://thorsten-willert.de/Themen/FFau3/Page_Analyzer/files to find the index. Edited September 23, 2009 by Stilgar jEdit4AutoIt PlanMaker_UDF
Kashgari Posted September 23, 2009 Author Posted September 23, 2009 Dear Stilgar, Thank you very much for your reply and help. It worked. I have been searching the form and reading for last so many hours, maybe sometimes it is better to just ask.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now