I've a webpage which has 2 text boxes. When i open the webpage cursor points to the first textbox. I need to fill these two textboxes and click on submit. I've written the code, but not working. I don't know the textboxes names as its on the server controlled by the company and no access to me. I would require something like a
fill a text box then do a tab fill anther text box do a tab and then click submit button. Any help?
#! /usr/local/bin/perl
use LWP::UserAgent;
use WWW::Mechanize;
my $agent = WWW::Mechanize->new(autocheck => [1]);
my $url = 'http://example.com/pages/editpage.action?pageId=197431143';
$agent->get($url);
$agent->submit_form(
fields => {
username => $username,
password => $password,
},
button => 'Log In'
);
Host confluence.broadcom.com is NXDOMAIN, so I am not able to verify your or my code. I think the mistake is that you picked the wrong variant of submit_form, it should look rather thus:
$agent->submit_form(
with_fields => {
username => $username,
password => $password,
},
);
The simplest approach here is to log into the page manually and then view the page source (Click Tools->View Source in Chrome for example). You should be able to identify the names of the text boxes by looking at the source.
If you scan the source (Ctrl-F) to find the prompt for the text box you should be able to easily find the associated input field. From there check the input attributes for a "name" or "id" attribute and use that for your input field.
So if you had a password text input box defined by something like:
<input name="j_password" id="passwd" ....>
your code to enter the password would look like:
j_password => $password
It's not my experience that the field names for a log in page change all that often so use the identified field names in your script and you should be good to go.
the clue is:
my $hostname='your dns host name';
my $LoginPage = 'https://$hostname/login.action';
my $cookie_jar = HTTP::Cookies->new(file => 'cookies', autosave => 1, ignore_discard => 1);
my $agent = WWW::Mechanize->new(cookie_jar => {}, autocheck => 0);
$agent->{onerror}=\&WWW::Mechanize::_warn;
$agent->get($LoginPage);
$agent->form_name('loginform'); #selest proper form
$agent->field(os_username => $user); #set user name field
$agent->field(os_password => $pass); #set password field
$agent->click("login"); #click button 'Log In'
then $agent you can use with get method:
$agent->get($someURL);
$content=$agent->content;
Finally in variable $content you have page source. It is no matter it is browser viewable page or json got by rest interface (it is url depended)
You must look into source on login page. simple put login page url into browser, then on example in firefox run tool named FireBug, or more complicated view page source. Then all names with this code example have sense :) The most component are addressed by name, not by id tag.
Some cookie is needed, because the most pages that needs login, stores authentication key as web cookie, because web communication is stateless.
Of course this example works for me with current confluence version 6.x series. Probably this should work with older confluence 5.x .
Related
This is the button I want to click:
<input type="submit" value="Continue">
As you see it has no name at all to specify the order on it. I am using the WWW::Mechanize module. I tried $agent->submit();, but it seems to not do the job, any help please?
It is not necessary to explicitely click the button to submit a form, let Mechanize handle it implicitly:
$mech->submit_form(
with_fields => {
username => 'foobar',
password => '12345678',
}
);
Run mech-dump to see the relevant form input field names, for instance here in my example username and password.
I have created a custom module that sets a system variable using variable_set(). I would like someone with the proper permissions to be able to edit this variable via the admin. I'm sure there are contributed modules that allow you to edit system variables, but I was looking for a way to include this functionality right in my custom module. I would like to maybe hook into the "Site Information" admin form or maybe the "File System" admin form and include a text field where they could edit this system variable and it would save. What's the best way to go about this?
THANKS
The Site Information form uses system_settings_form() which means you just need to add your variable as an element to the form (using hook_form_alter() or, as in the following, hook_form_FORM_ID_alter()) and the system will handle saving it.
function MYMODULE_form_system_site_information_settings_alter(&$form, &$form_state) {
$form['my_variable_name'] = array(
'#type' => 'textfield', // or whatever element makes sense
'#title' => t('Title'),
'#default_value' => variable_get('my_variable_name', '')
);
}
Same thing goes for the system_file_system_settings() form.
I am trying to use JFormFieldUser::getInput as an input to my Joomla forms.
In the backend (logged in with the super user), when I call this method, it produces a nice 'select user' box when clicked displays a list of all users to chose from.
I have been trying to use the User form field on a front end form (logged in with the super user). The result is some what confusing and undesirable. A 'select user' link is produced, but when clicking on it, the result is that the super users, 'User profile' is loaded up: not a list of all users.
Why is this, and how can i make 'select user' show the full list of users like it does in the backend.
Joomla 3 (from your field definitions):
<field name="field_name" type="sql" label="COM_FIELD_LABEL"
sql_select="id,name"
sql_from="#__users"
value_field="name"
key_field="id"
description=""
header="DROP_DOWN_HEADER"
required="false" />
Apparently it can't be done
The JForm (Joomla) User field is the Joomla core field that you can
see in Joomla article form to select a user (lightbox with list of
user). Becareful this field can not be used on front-end because
Joomla core don't manage it on front-end... Often we replace this
field on front end with a select dynamic field.
I didn't have much luck with this. Instead I created my own component and added in the content from com_users. Worked a treat.
Can be done fairly simply but with some significant limitations - depending on your use case.
User must be logged in to backend (even if you are trying to access the information frontend). If they are not logged in, it will prompt for log in and break out of the modal :(
User must have permissions for User Manager
Then duplicate the \libraries\cms\form\field\user.php to a fields location of your choice (in a modal subdirectory) and rename it to something like user2.php. Make the class name JFormFieldModal_Users2 and the $type='Modal_Users2'.
Don't forget to add the new path to your form .xml if required. The type will be "modal_users2".
Last step. In user2.php, change:
$link = 'index.php?option=com_users&view=users&layout=modal&tmpl=component&field=' . $this->id
. (isset($groups) ? ('&groups=' . base64_encode(json_encode($groups))) : '')
. (isset($excluded) ? ('&excluded=' . base64_encode(json_encode($excluded))) : '');
to
$link = 'administrator/index.php?option=com_users&view=users&layout=modal&tmpl=component&field=' . $this->id
. (isset($groups) ? ('&groups=' . base64_encode(json_encode($groups))) : '')
. (isset($excluded) ? ('&excluded=' . base64_encode(json_encode($excluded))) : '');
A bit hacky, but served my purposes.
Less hacky, but less glamorous solution here: The SQL formfield type
I am having a Log-in form and want to add a "Lost Password" Link inside. I found out that you can use the description to do so. But I have now started to change everything to work with routes and would like to use this also for the Forgot Password Link. is there any chance to do this? I can't find a solution, anyone of you who knows how to do it?
$password = new Zend_Form_Element_Password('login_password', array(
'label' => 'Password',
'description' => 'Forgot Password ?',
'required' => true,
));
$password->getDecorator('description')->setOptions(array('escape' => false, 'placement' => 'APPEND'));
I've faced the same problem before, and got answer at
Write hyperlink inside the Zend Form?
May help you also...
When creating a Zend_Form, you don't have access to View_Helpers, as a form does not require a view instance. Therefore you either have to fetch a view in your form's init-method or add the description later (I prefer the latter).
When doing it the first way, you have to fetch the Zend_Controller_Front-instance and then its view, finally call a view helper, e.g. Zend_View_Helper_Url from that view.
The latter can be achieved by adding the description later on, e.g. when you passed the form to your view (or in your controller before passing it to the view):
<?php
$description = '<a href="' . $this->url([...]); . '"'>forgot password?</a>
$this->form->getElement('login_password')->setDescription($description);
echo $this->form;
?>
I'm new to Perl, currently writing a Perl script to automatically fill web forms and submit them using LWP. The website URL is ***/something.cgi and in that document there is a form I need to fill, then hit submit. That takes me to another page which has another form to fill, but the website's URL remains the same.
I managed to fill the first form and submit it using:
$res = $ua->request($f->press("submit"));
where
my $f = HTTP::Request::Form->new($forms[0], $url);
Viewing $res->as_string shows the next page source, but tried to get the new forms in order to fill it, but it gave me the same form I already have. How can I get next page in order to fill its forms and proceed?
I would recommend you look at WWW::Mechanize and its form methods which is a subclass of LWP::UserAgent.
EDIT
Adding an example closely based on the example from my first link:
use strict;
use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$mech->get( 'http://google.com' );
sleep 1; ## be nice
$mech->submit_form(
form_number => 0,
fields => {
q => 'mungo',
}
);
print $mech->content;
The form you are trying to script must be using some paramter or cookie to determine which page of the multi-page form to process. Look at the cookies returned in
print $res->header();
to see if there are cookies being set for a session-ID or other parameter that you need to pass back in.
Also, look at the source of the first form page vs the second, see if there are hidden input types that indicate that the second submission is for the second form page. Or, look at the value of the submit button tag, maybe that is different on the second page.