I have an read-only text-field in my site. And I need to enter a date using cucumber and watir. But I can't set any value. Even passing the value of date with value = method I can't input any output. There is a JavaScript calendar.
I wrote:
browser.text_field(:name => "deal[start_date]").value = 'test'
it shows the following error:
Watir::Exception::ObjectReadOnlyException: Watir::Exception::ObjectReadOnlyException
from /var/lib/gems/1.8/gems/watir-webdriver-0.1.7/lib/watir-webdriver/elements/element.rb:252:in `assert_writable'
from /var/lib/gems/1.8/gems/watir-webdriver-0.1.7/lib/watir-webdriver/elements/text_field.rb:24:in `value='
from (irb):10
Please help me, I am in a trouble.
This goes along with what xboxer21 noted. I found this code worked for me on a site that had a similar calendar widget.
Lets say you have an HTML form with input text fields that are set to readonly:
<form name="FindRange" method="post" action="FindRange.asp" onsubmit="return false">
...
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" class="FieldLabel">
<input type="text" name="FromDate" size="16" readonly="true" style="width:85px; background-color:#F8F6E7;">
</td>
<td>
<input type="text" name="ToDate" size="16" readonly="true" style="width:85px; background-color:#F8F6E7;">
</td>
</tr>
...
</form>
Using code like '#ie.text(:name, "FromDate").set("3/23/2011")' in your Ruby Watir script would result in an error in Ruby stating the field was read-only. But using the eval() method may allow you to use Javascript to set the read-only fields behind the scenes.
#Code above these lines instantiate the Watir object in #ie and navigate to the page #containing the HTML form
#named 'FindRange'
#ie.document.parentWindow.eval("document.FindRange.FromDate.value = '3/23/2011'")
#ie.document.parentWindow.eval("document.FindRange.ToDate.value = '3/24/2011'")
Well, the text field is read only, as the error message says. That means it can not be changed. How would you change the value of the text field without Watir? Can you provide link to the page or relevant HTML?
This is what I did to enter a date in a read only text field, The JS calendar script used was http://www.dynarch.com/projects/calendar/
There is a small icon next to the date field which displays the calendar widget upon clicking it.
browser.image(:id,"datewidget-trigger").click # Will display the Calendar
browser.send_keys("{ENTER}") # Will select current date
If you want to select a future date or previous date
browser.send_keys("{LEFT}")
browser.send_keys("{RIGHT}")
This has been tested using IE only.
Try executing the JavaScript itself.
browser.document.parentWindow.execScript("Date_JS_script('date')")
Related
I'm trying to build a data scraper with Selenium Python that searches a webpage. The search page contains a dojoComboBox that allows you to select a name from a dropdown list.
Here is the HTML for the dojoComboBox:
<span _="whitespace and CR's between tags adds in FF" class="dojoComboBoxOuter dj_khtml dj_safari dropSel" style="null">
<input style="display:none" tabindex="-1" name="txtCaseName" value="" dojoattachpoint="comboBoxValue">
<input style="display:none" tabindex="-1" name="txtCaseName_selected" value="" dojoattachpoint="comboBoxSelectionValue">
<input type="text" autocomplete="off" class="dojoComboBox dropSel" dojoattachevent="key:_handleKeyEvents; keyUp: onKeyUp; compositionEnd; onResize;" dojoattachpoint="textInputNode" style="null">
<img hspace="0" vspace="0" class="dojoComboBox dropSel" dojoattachpoint="downArrowNode" dojoattachevent="onMouseUp: handleArrowClick; onResize;" src="dojo/src/widget/templates/images/combo_box_arrow.png" style="width: 13px; height: 13px;">
</span>
I can get the DojoComboBox scroll menu to open with the following code:
dropdown = browser.find_element_by_css_selector("img.dojoComboBox")
dropdown.click()
However, I can't seem to find a way to actually select one of the values.
Update:
The HTML I posted above is from the page I pull up when I inspect elements (the HTML under the 'Elements' tab of Chrome DevTools). I've been looking at some other files that I found in the 'Source' tab, and I found some code in a page called main.aspx?e=nauqov2blnhlnh45eseztnao that looks also related to the DojoComboBox:
<select name="txtCaseName" id="txtCaseName" class="dropSel"dojotype="ComboBox"
setSelectedValue="dojo.byId('txtCaseName1').value=arguments[0]"
autocomplete="true" dataurl="CaseCode.aspx?match=%{searchString}&lang=e"
mode="remote" maxlistlength="7">
</select>
However, neither of these seem to encode options that I can select. I thought that perhaps the options would be stored in the url labeled 'dataurl' in the piece of HTML above, but when I copy that link into my address bar, it doesn't take me to a valid webpage. From what I've found in the Dojo documentation, it seems like the options should be stored in a separate file/database, but I can't find any suggestions about how to access that file.
Any suggestions? (Thanks!)
you will have to store every options in a list. Then based on some conditions such as name of option, you can choose it and click on it.
all_options = browser.find_elements_by_css_selector("your locator for every options")
for options in all_options:
if "option_name" in options.text.strip():
options.click()
I'm trying to add a new field named "AlternateLink" to our news page types.
Currently the "Read More" button goes to the full article page with the following:
Read More
I've updated it to:
Read More
but even with a link in the Alternate Link field (see attached image), it always links to the full article page instead of the alternate link.
I tried the same IfEmpty statement with other existing field names such as "NewsTitle" or "NewsImage" and those seem to work so the issue seems to be "AlternateLink" field name.
I created a field with the ID of "AlternateLink" as a text box. Am I missing another step to make it capture the value?
EDIT: AlternateLink is the only new thing I'm adding. All of the existing values (NewsTeaser, NewsTitle, NewsSummary, etc.) all work. Full code:
<div class="blog-post col-md-12 clearfix">
<cms:Media ID="mTeaser" runat="server" Url='<%# Eval("NewsTeaser") %>' Class="img-responsive" />
<h2 class="blog-title"><%# Eval("NewsTitle",true) %></h2>
<div class="post-info">
<i class="fa fa-clock-o"></i><%# GetDateTime("NewsReleaseDate", "MMMM dd, yyyy") %>
</div>
<p><%# Eval("NewsSummary") %></p>
Read More
<span class="hr col-md-12 col-sm-12 col-xs-12"></span>
</div>
You don't need Eval for Text/XML transformations.
Have you checked columns field of the web part, that shows news on the page? Make sure AlternateLink column is also listed there.
Have you tested using just <%#Eval("AlternateLink",true)%> to see what it returns?
Looks like your code is {%Eval("AlternateLink",true)%} when it should be {%AlternateLink%}. <%#%> is for ASPX Transformations. {%%} is for Text/XML transformations, which it looks like you are using.
Could you please try this.
Read More
I have created a libary with about 80 sublime-snippet's.
They work great on my machine which is the machine I created them on. I then passed my folder out to two of my fellow employees so that they could use the new library of snippets I created. The only issue is the snippets won't work on their machines. They are installing it in /Sublime Text 3/Packages/MySnippetFolder. These snippets are meant to be used in .html files. However they are only showing up in .py files for my coworkers. Scope is commented out in the sublime-snippet files so shouldn't they appear in .html files as well? Any advice is appreciated thank you very much for your time in advance.
Edit: Ok So the snippets are working as intended I believe. The thing I am confused about now is when I use it in a python file a dropdown list appears that contains my snippets. When I try this in my html files there is no drop list containing my snippets. Is there a way to have to drop down list appear in my html files as well like it does for the bootstrap 3/4 snippets package?
Here is an example of the code for one of my snippets.
<snippet>
<content><![CDATA[
<div class="form-group v-spacing-extra-large">
<p>Minimum: <strong>1</strong> | Maximum: <strong>10</strong> | Multiple <small>(Step)</small>: <strong>1</strong>
</p>
<div class="input-stepper-group">
<a aria-label="Decrease Quantity by 1" tabindex="0" data-stepper-role="decrease" data-stepper-target="#demo-stepper-three" href="#" class="btn btn-secondary js-stepper-control disabled"><i aria-hidden="true" class="icon-minus"></i></a>
<input aria-describedby="product-qty-three-stepper-aria-describedby" aria-label="quantity" data-toggle="stepper" data-round="up" id="demo-stepper-three" class="form-control stepper" pattern="[0-9.]+" type="text" data-min="1" data-max="10" data-step="1" value="1">
<a aria-label="Increase Quantity by 1" tabindex="0" data-stepper-role="increase" data-stepper-target="#demo-stepper-three" href="#" class="btn btn-secondary js-stepper-control"><i aria-hidden="true" class="icon-plus"></i></a>
</div>
<span id="product-qty-three-stepper-aria-describedby" class="ada screen-reader-only">Initial Quantity is set to 1. Max Quantity is set to 10 and the step multiple is set to 1.</span>
</div>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>ff-stepper-min1-max10-stepby1</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
To have the dropdown list appear in your html files unless you have another package installed to enable this just type < before your snippet code. So if you have a my-snippet.sublime-snippet , then to use that you would type "<"my-snippet wihtout the "'s and you would see the drop down once you began typing.
Just press CTRL + Space anywhere in the code to get the snippets dropdown.
My dilemma:-
I have 4 stored registrations from a results list ${VEH_REG_1}, ${VEH_REG_2}, ${VEH_REG_3} & ${VEH_REG_4}.
I am adding these registrations to a list via a UI. So you select the four vehicles and click a button, a popup then appears letting you know if you are successful or not in adding the vehicles to the list. The popup lists the registrations in a "P" tag with "BR" tag between the registrations, so each registration is on a new line.
My problem is, the stored registrations I have are not always displayed in the logical order I saved them, so verifying the text is not as straight forward as it would normally be.
I have tried verifytext with direct xpaths. I have tried verifytextpresent (but as the results list is still present, it finds the registrations even if they are not in my list) and I have tried to use the gotoif command, but I still have the same problem when it comes to the "BR" tags.
<div class="mbtn">
<div style="height: 120px; overflow: auto">
<span id="ctl00_phmcp_phmc_lblOfflineMarketingResult">
The selected not-pending cars have been added to the offline marketing list.
<br>
The following vehicles are not in the appropriate status:
<p>
LJ57OOB
<br>
RF56RZC
<br>
LJ58PJY
</p>
<p>
</span>
</div>
As I do not have 10 reputation to display images yet (Grrr!!!!) I can email you the image if it helps to understand what I am trying to achieve.
Any help is appreciated.
Thanks Mark
verify them one at a time with globs so you don't need to verify the order.
<tr>
<td>verifyText</td>
<td>//span[#id="ctl00_phmcp_phmc_lblOfflineMarketingResult"]</td>
<td>*LJ57OOB*</td>
</tr>
<tr>
<td>verifyText</td>
<td>//span[#id="ctl00_phmcp_phmc_lblOfflineMarketingResult"]</td>
<td>*LJ58PJY*</td>
</tr>
I am working on a Google chrome extension. the idea is that I enter my username and password, click submit and have a new tab open with my website, which will then pick up the submitted form and log me in.
I have managed to open my website in a new tab, but can not get it to pick up the form.
You can use OnClick event in submit button:
<input type="submit" value="submit" onclick="this.form.target='_blank';return true;">
You can create an HTML form in your popup.html as follows:
<form name="input" action="http://example.com/login.php" method="get">
Username: <input type="text" name="user">
Password: <input type="password" name="password">
<input type="submit" value="Submit"></form>
And in the script of your website you can check if the parameters and have been passed, and if correct then create redirect them to the DashBoard on your site, otherwise show them the login page to enter the correct credentials
Since you've got your website loaded, try using jquery to select the textbox and enter a value.
The following selects the where the input is, then finds the input I want, then finally sets the value inside of that box.
$("td[data-key='sku']").find("input.tb-input").val('some text here')
In the jquery code above, the html would look something like this:
<td data-key='sku'>
<input class=tb-input/>
</td>