Folks,
My web app has a date widget and I am trying to enter a date and I get the above exception, my HTML code looks like this:
<form id="order_form" class="h" method="post" action="/order/orders/1000">
<div style="margin: 0pt; padding: 0pt; display: inline;">
</div>
<input id="order_type_description" type="hidden" value="Order" name="order[type_description]">
<fieldset>
</fieldset>
<fieldset id="simple">
<legend>Order terms</legend>
<div class="field clear">
<label class="_"> </label>
<textarea id="order_sorder_for" rows="5" name="order[order_for]" cols="80"></textarea>
</div>
</fieldset>
<fieldset id="basic" style="display: none;">
</fieldset>
<fieldset id="change" style="display: none;">
</fieldset>
<fieldset>
<legend>Optional</legend>
<fieldset>
<div class="field clear">
</div>
<div class="field clear">
<label class="_">Range</label>
<select id="smart_date" onchange="process_date(this, true);" name="order[smart_date]">
</select>
<p class="tip"> Select . </p>
</div>
<div class="field clear">
<label class="_">Begins on</label>
<input id="order_begin_string" class="custom_date_range calendar hasDatepicker" type="text" size="30" readonly="readonly" name="order[begin_string]">
<img class="ui-datepicker-trigger" src="/images/calendar.gif" alt="..." title="...">
</div>
<div class="field clear">
<label class="_">Ends on</label>
<input id="order_end_string" class="custom_date_range calendar hasDatepicker" type="text" size="30" readonly="readonly" name="order[end_string]">
<img class="ui-datepicker-trigger" src="/images/calendar.gif" alt="..." title="...">
</div>
How do I enter the date? I was considering running javascript in the watir code like this:
##browser.execute_script("document.order_form.order_begin_string.value = 'March 01, 2011'")
But the above does not work, I get the following error for that:
document.order_form is undefined (Selenium::WebDriver::Error::UnexpectedJavascriptError)
Any help is much appreciated. thanks a lot
The locating of the element should be done using the getElementById (or similar) method.
The following worked with your sample HTML (tested in Firefox):
##browser.execute_script("document.getElementById('order_begin_string').value='March 01, 2011'")
Related
this is my email form
<form action="https://gmail.us11.list-manage.com/subscribe/post?u=XXXXXX" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
<div id="mc_embed_signup_scroll" style="display: flex;flex-direction: row;">
<div class="mc-field-group">
<input type="email" value="" name="EMAIL" class="required email" id="mce-EMAIL">
<span id="mce-EMAIL-HELPERTEXT" class="helper_text"></span>
</div>
<div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_fb16c0b54b243c41cf0ba431c_6cbe3da72c" tabindex="-1" value=""></div>
<div class="optionalParent">
<div class="clear foot">
<button type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="rehab-btn-secondary">Send</button>
</div>
</div>
</div>
</form>
however if I input "aaa" as email address which is wrong. I am getting this error
Which obviosly breaks our UI,
by checking on the HTML in dev tools, it creates a new div with id "mce-inline-error"
out of the blue, how can i control this error so i can style it properly in our UI?
This is getting annoying google cant give me answer.
If there are no answers, what type of work around can you guys suggest?
I have a xml like this and am trying to select the groupIdentifier element without the display:none child (would like to use the css "identifier" along with it) to finally select the input. Have been at this for hours and would like to call the xpath gods to help me out.
<div class="groupIdentifier">
<div>
<input class="inputClassIdentifier">
</div>
<div>
...
<div>
<div class="something">
... some more elements
</div>
<div class="identifier hidden" style="display: none">
... some more elements
</div>
<div class="something">
... some more elements
</div>
</div>
</div>
</div>
<div class="groupIdentifier">
<div>
<input class="inputClassIdentifier">
</div>
<div>
<div>
<div class="something">
... some more elements
</div>
<div class="identifier ">
... some more elements
</div>
</div>
</div>
</div>
Thanks
edit:
I have
//div[contains(#class, 'identifier') and not(contains(#style, 'display: none'))] which basically selects the identifier div of the second section.
What I need now is to select the input with class inputClassIdentifier within its parent.
Here's your xpath.
//div[#class='groupIdentifier' and div/div/div[not(contains(#style, 'display: none'))]]
I got it using descendant axis
//div[#data-testid='groupIdentifier' and descendant::div[contains(#class, 'identifier') and not(contains(#style, 'display: none'))]]//input[#name='inputClassIdentifier']
I have 4 other elements the same as below though they differ in title
<div id="r7695cf6b-f4a79" class="featureFoo ">
<div class="overview">
<h3 class="title">My Library</h3>
<p class="description">Some description</p>
</div>
<div class="foo">
<form>
<div id="ra41984bc58005" class="switch label-position-right non-required" aria-describedby="">
<input name="fooEnabled" type="checkbox" id="r14e560d0-bfbc-476a-a066-cbb3c043006c" checked="" class="">
<div class="foo-switch">
<div class="indicator"></div>
</div>
<span class="error" title=""></span>
</div>
</form>
</div>
</div>
I am trying to retrieve the nonhidden input element and to see if it is checked. I have this xpath
$x("//div[contains(#class, 'featureFoo')][./div/h3[text()='My Library']]//input[contains(#name,'fooEnabled')]")
which works in the Chrome console but it does not work in Ruby Cucumber's find() method
find(:xpath, "//div[contains(#class, 'featureFoo')][./div/h3[text()='My Library']]//input[contains(#name,'fooEnabled')]")
Is there more conversion that needs to be done to the xpath so it will work in cucumber's find() or could there be a better approach to this?
Could you please create complete XPATH for the following web element
Address 1 (PO Box/Rural Route is ok)
it would be great if you give me how to create the XPATH as well for any HTML or XML code.
HTML code:
<!DOCTYPE html>
<html>
<head>
<body id="myProfile">
<div id="header">
<div class="wrapperMenu">
<div class="wrapperBodyCreditCenter">
<div id="bodyAll2">
<div>
<div class="fsmWideHero">
<div style="display: block; margin-bottom: 10px;">
<div class="fsmSubHeader"> Please update any information to maintain a clean and current profile. Once the correct information is entered, simply click on the save changes button to update your profile. </div>
<span class="validateError"> </span>
<script src="https://staging.privacyguard.com/ClientScript.aspx?script=FormControl%2fdisableOnSubmit.js&utc=633470607600000000" type="text/javascript">
<form action="/secure/MyProfile.aspx" autocomplete="OFF" name="PGUpdateProfileFormControl" onsubmit="disableSubmission(this)" method="post">
<input type="hidden" value="pgupdateprofile" name="cf">
<input id="__FLOWEVENT" type="hidden">
<input type="hidden" value="5sXZAFNB4Co/JF70jyZ1HHJdIMso9YP2jGmMsyuLQCKC2J0lOg2XDVX2FcLJBS2WMnYD55d7UNLPVXW0yHa6f4WVjmWwwvT0KiwnAY+6v0xpWJZ9fuKe5F2h25Z+aZZwdoEpJtmnYVyvq+znPaYwyQqTV0d3M6bWeBKMt6woDqdtRzUEooyojAzyaMiYFyqosVe5cGarbQWvFZiUJqH3wGRawchSjnjzh/Amy2F8YHZlJFJVWYAQ4PUx8E9GQeShHsCMs2Fg3ToiUemtIpgXaCGMnCby+sCEnRW4SPA3P9/Et2VO/YXsCYSwkfsNsqSAWMnYoicNwJy9ALYny1uAUxgBrv4dELuz+St9CcUrB0w=" name="__FlowState__">
<input type="hidden" value="364" name="__fspayload">
<div id="profileFormHeader"> Personal Information </div>
<div id="profileFormBody">
If you wish to change your name, contact the FreeScoresAndMore customer service center at 1-877-787-9002.
<p>
<p> </p>
<table cellspacing="0" cellpadding="2" border="0" summary="">
<tbody>
<tr>
<td width="220" align="left">
<label for="mpadr1">Address 1 (PO Box/Rural Route is ok)</label>
<br>
<input id="mpadr1" type="text" value="123 new address" name="UpdateProfile_Address1" maxlength="25" size="28">
</td>
<td align="left" colspan="2">
<td width="200" valign="top" bgcolor="#FFFFFF" align="left" style="background-color:#EFF0F2;" rowspan="3">
</tr>
<tr>
<tr>
</tbody>
</table>
</div>
<div id="profileFormHeader"> Membership Information </div>
<div id="profileFormBody">
<div id="profileFormHeader"> Subscription Preference </div>
<div id="profileFormBody">
<div style="text-align:center;margin-top:10px;">
</form>
</div>
<input type="hidden" value="7iuanXFUppuCMU7T/6LZi09GsdZ2dCYBLeTL/Wfbclc=" name="authToken">
</div>
</div>
<div class="clear" style="padding-bottom:20px;"></div>
<div id="subFooter">
<div id="mainFooter">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript">
<script type="text/javascript">
<script type="text/javascript">
</body>
</html>
Thanks In Advance
I don't think there's a magic-ally way of doing things. There's a lot of guides/tutorials out there where you can start learning.
Nonetheless, here's the xpath code that you need //label[#for='mpadr1'] or //label[contains(.,'Address 1')]
Html code is as follows:
<li>
<form action="/en/pune/dsf/media/create" enctype="multipart/form-data" method="post">
<div style="margin: 0px; padding: 0px; display: inline;">
<input name="authenticity_token" type="hidden" value="DD9PUpCMWTGs66fHEZutO+9RFjcf68xH+T9DMXv1JnA="/>
</div>
<div class="media_upload_submit">
<span class="icon-camera"/>
<span class="al">Add photos</span>
</div>
<input class="media_image_file" data-track="photo_upload,spot_page,user" name="media[image]" type="file"/>
</form>
</li>
I have tried using
#browser.file_field(:xpath, "//input[#type='file' and #class='media_image_file']/").set "Complete file path name"
but I get the following error:
Failure: Unable to locate an element with the xpath expression //input[#type='file' and #class='media_image_file']/ because of the following error:
I have tried using many different ways but get different errors.
There is a extra / after ..and #class='media_image_file']/". Remove it and write like :
#browser.file_field(:xpath, "//input[#type='file' and #class='media_image_file']")