I'm attempting to use VB.Net WebBorwser to populate and submit a webform. I'm using webbrowser because I don't know much javascript or c#. I'm open to other ideas of course.
I'm able to populate the form fields easily enough:
m_oWebBrowser1.Document.GetElementById("line1").SetAttribute("value", "Flat 12")
but this isn't enough to trigger the page to set the require variables. I've also tried:
m_oWebBrowser.Document.GetElementById("line1").InvokeMember("change")
and
m_oWebBrowser.Navigate("javascript: PreviousAddress().Address().Line1='Flat 19';")
The input field looks like this:
<input id="previousAddressLine1" class="col-xs-12 col-sm-8" name="previousAddressLine1" tabindex="12" data-bind="value: PreviousAddress().Address().Line1" type="text">
Any help would be great.
-Ben
Related
I have a page with multiple textboxes and dropdowns with values that I am trying to validate. The values in them will be dynamic in each run.
The HTML looks something like:
<input readonly="readonly" class="form-control valid" data-val="true" data="ABC" aria-invalid="false" xpath="1">
What I want to do is grab the value of "data" for each textbox. I have used scriptAll before in such a case when I was grabbing text by using innerText. However, that won't work with a regular value such as in the HTML above.
I did try one solution that worked:
driver.value(//input[#data])
However, that just grabs the first textbox value, is there a way I can combine scriptAll with driver.value? OR would I be better off doing some JS here?
Thank you in advance!
Yes, refer the docs for scriptAll(): https://github.com/karatelabs/karate/tree/master/karate-core#scriptall
Use whatever JS works to get an attribute value. Haven't tried, but this should work, you get the idea:
* def list = scriptAll('input', "_.getAttribute('data')")
I have an input element where I need to set one extra attribute and its value.
<input autocomplete="off" id="to_input" name="to" class="form-control arrival ui-autocomplete-input" placeholder="To" data-input-component="searchCondition" data-input-support="suggest" type="text">
I need to add the below attribute:
How can I do this in Geb?
To say a little more details, when I enter TPE in the input text box, some dropdown items appears and when I select one of them like
"Taipei, XXX.. (TPE)"
Than the new attributes are set automatically same as the picture above.
The only way to do it, is using JavaScript executor:
browser.driver.executeScript("your script")
And script using jquery will look like:
$('jquery-selector').attr('attribute-name', 'attribute-value');
Of course make sure to fill in your data in quotes!
Looking for the best approach to enter / read a value from a form field that lacks human readable ids / references.
The basic outline looks like
<div id="form-2143">
<div id="numberfield-1234">
<label id="numberfield-1234-label">
<span class="x-form-label">Field Name 1</span>
</label>
<div id="numberfield-1234-body">
<div id="numberfield-1234-wrap">
<input id="numberfield-1234-input" class="form-field" componentid="numberfield-1234">
</div>
</div>
</div>
...
</div>
There are more class defs and attributes involved, but above is the "basics" I have to work with.
This form has a number of entries, and there are more forms like it, so I am looking for a way to search for the label name, and access the input field within the same container.
I lack control of the site and cannot edit the HTML structure of the site; meaning I cannot give sensible names to the ids, but want to avoid hard referencing the poor names. Any suggestions on how to get Robot Framework & selenium to reference these elements?
Highlighting Andersson's answer in the comments
Using the XPath
//label[span[text()="Field Name 1"]]/following-sibling::div//input
Works for the above example.
The key part that answers the question of how to reference nearby elements is
/following-sibling
I'm stuck with a Yii 1 implementation that has a CJuiDatePicker. I notice it creates <input type="text"> but I want it to create a <input type="date">. Is this possible?
I tried using htmlOptions to set it but that didn't seem to make a difference.
I'm using https://pypi.python.org/pypi/tgapp-resetpassword/0.1.5 which allows you to override the template used for the reset password page. Unfortunately, the actual form itself is included as a 'black box':
<div>
${reset_password_form.display(action=action)}
</div>
The form has been defined as a tw2.forms.TableForm which is not how I'd like to display it. Is it possible to have finer grain control e.g. insert custom html around each of the fields, or be more explicit about how to display certain fields?
E.g. I'd like to do something like the following (made up):
<div>
<form ${reset_password_form.attrs} class="my-own-class-name">
<py:for each="field in reset_password_form.fields">
<div class="custom-class-here">
<label for="${field.id}">
... some logic to possibly override default label else...
${field.default_label_text}
</label>
${field.render_as_input_field()}
</div>
</py:for>
<button type="submit">My own submit text</button>
<form>
</div>
Is this level of customization possible with ToscaWidgets without overriding things in Python?
As by resetpassword documentation you have a reset_password.reset_password_form option that can be used to specify an alternative tw2 form.
You just need to put there the python path (like "resetpassword.lib.forms.ResetPasswordForm") of the form you would like to use in place of the default form.
Then you own form can specify a custom template like https://gist.github.com/amol-/d2a08027d34a8c4dfa69