Selecting the prompt with Capybara - ruby

I have a select dropdown:
<%= f.select :image_size_id, options_for_select(#image_sizes.collect{ |i| [i.dimension, { id: i.dimension} ]}), { prompt: "Please select a Print Size" }, id: 'image_size_select' %>
Which returns this in HTML:
<select id="image_size_select" name="cart_item[image_size_id]">
<option value="">Please select a Print Size</option>
<option id="10x8" value="13">10x8 £14.0</option>
<option id="A4" value="14">A4 £33.0</option>
<option id="A3" value="15">A3 £36.0</option>
<option id="A2" value="16">A2 £47.0</option>
</select>
At the moment to select an option within my tests I can use for example:
find('#image_size_select').find("option[id='A2']").select_option
find('#image_size_select').find("option[value='14']").select_option
What I want to do though is select the prompt so that I can test my validation, can I set an id of the prompt or select by text ? I have tried:
find('#image_size_select').find("option[text='find('#image_size_select').find("option[id='A2']").select_option']").select_option
But that doesn't work, nor does:
find('#image_size_select').find(:xpath, 'option[1]').select_option

Capybaras #select chooses the option by the text, not value, of the option element. When passed with a :from option it is implemented as find(:select, '<select id, name, or associated label text (the :from option)>').find(:option, '<text of option element>').select_option which means the correct call to select the first option in the specified select is
page.select "Please select a Print Size", from: 'image_size_select'
to select the next option
page.select "10x8 £14.0", from: 'image_size_select'
Due to Capybaras default partial string matching
page.select "10x8", from: 'image_size_select'
would also select the 10x8 option as long as "10x8" is a partial match to only one of the options in the select

page.select "", from: 'image_size_select' should work. select allows you to select options from a select drop-down based on value (which in this case it's actually an empty string) and the select drop-down can be found in the page via name, id or label.
The documentation of the method is at http://www.rubydoc.info/github/jnicklas/capybara/Capybara%2FNode%2FActions%3Aselect

Related

Apex Item in interactive report not being displayed correctly

I'm creating a interactive report and I want to dynamically create apex items (text fields) in it, but they are not being displayed correctly.
This is my code:
select
APEX_ITEM.text( p_idx=> 1 , p_value=> null, p_item_id => 'dynamic_item') as "Textfield"
from dual
connect by level = 3;
This shows up in the report:
<input type="text" name="f01" size="20" maxlength="2000" value="" id="dynamic_item" />
But I would like to get the actual item and not the code?
What am I doing wrong?
It looks like you didn't set the escape special characters property to "No".
Go on your report and select the column you created (Textfield).
Then on the right at "Security - Escape special characters" select "No".
Now it should be displayed correctly!

Doesn't select the Right option in dropdown

Protractor select the wrong option in dropdown.
I have to:
select the first dropdown to open another dropdown (in my situation: select Payment Method (1st dropdown) to open the 2nd dropdown - available credit cards):
The IMPORTANT moment: if the 1st dropdown has a default value - the 2nd dropdown CAN NOT be visible.
My piece of code had different variation:
let paymentDropdown = element(by.name("payment-method"));
let dynamicBlock = $$(".dynamic").first();
let useThisCardButton = element(by.name("do-add-payment-method»));
let paymentConfigBlock = element(by.id("payment-config-container"));
browser.wait(EC.visibilityOf(paymentDropdown), 5000);
$("#payment-method-0 > option:nth-child(2)").click();
browser.wait(EC.visibilityOf(dynamicBlock), 5000);
useThisCardButton.click();
browser.wait(EC.visibilityOf(paymentConfigBlock), 5000);
So, I’ve tried for the first dropdown:
1. $("#payment-method-0 > option:nth-child(2)").click();
2. element(by.name("payment-method"))
.all(by.tagName('option'))
.get(1)
.click();
3. element(by.cssContainingText('option', 'Credit Card')).click();
4. element(by.name("payment-method")).$('[value="cc"]').click();
Html is:
<select name="payment-method" id="payment-method-0" style="display: inline-block;">
<option value="0">Select Payment Method</option>
<option value="cc">Credit Card</option>
</select>
And Nothing! I don’t know how does it work, but the 1st dropdown has Default Value, and the 2nd dropdown is VISIBLE! Then I click on «Use this method» button and got Fail!
1 test from 10 tests choose the right 1st value, so test passed. But other 9 trials are failed. Why? How to do it correct and how to be sure that it will select the right option?
Try the below one. Here you can select the values without opening the drop down.
var firstDrop = element(by.css('#payment-method-0'));
browser.wait(EC.elementToBeClickable(firstDrop), 5000);
firstDrop.sendKeys('Credit Card');
browser.wait(EC.visibilityOf(dynamicBlock), 5000);
Hope it helps you

Xpath to Scrape Size Information with Scrapy

I aim to scrape the following bit of code:
Select Size:</b>
<select name="option[225]">
<option value=""> --- Please Select --- </option>
<option value="480">UK 11 </option>
<option value="478">UK 8 </option>
<option value="477">UK 7 </option>
</select>
I'm facing two problems:
1) the value in "option[225] isn't constant for all the pages on that site and changes from each product.
2) Is there anyway, I can store the data with semi-colon separators between each value.
I wish for the data to be displayed in the following manner:
UK 11;UK 8;UK 7
>>> ';'.join(map(str.strip, sel.xpath('//option[string-length(#value)!=0]/text()')))
'UK 11;UK 8;UK 7'
// for selecting all option tags starting from the root of the document, string-length to filter out first empty name option and ';'.join(...) to join generator elements with ; between them
If "Select Size:" is something that is constant before the select/options you want to select, you can try an XPath expression like this:
xpath_expression = """//b[contains(., "Select Size:")]
/following-sibling::select[starts-with(#name, "option[")][1]
/option[#value != ""]/#value"""
Then, as #Guy suggests, you can use:
u";".join([val.strip() for val in sel.xpath(xpath_expression).extract()])

Select a value from a select List by value element

recently I came upon an issue while using page object that I could not find an answer to.
When using a select list to choose an option. I need to select by partial text or by attribute. here is an example:
<select id="custcol95" name="custcol95">
<option selected="" value="">- Select -</option>
<option value="5">Monthly Basic Plan - $27.99</option>
<option value="1">Monthly Business Plan - $54.99</option>
</select>
I tried:
select_list(:planPurchase, :id => 'custcol95')
I can do this:
selectCloudPlan_element.option(:value, CLOUD_PLANS['PersonalMonthly']).select
but that is deprecated.
I have yet to see a select by value option or by index anywhere on the web. Does one exist?
Also if there was a search by partial text that would fix my issue.
Thanks in advance.
The page object gem already supports selecting by partial text:
page.planPurchase = /Basic/
puts page.planPurchase
#=> "Monthly Basic Plan - $27.99"
Selecting by value is also supported by using select_value:
page.planPurchase_element.select_value('5')
puts page.planPurchase
#=> "Monthly Basic Plan - $27.99"
The page object gem supports selecting options by index using []. Note that you have to use .click as there is no .select. The index is 0-based.
page.planPurchase_element[2].click
puts page.planPurchase
#=> "Monthly Business Plan - $54.99"

how to select dropdown on value option in ruby watir?

This is my drop down and i want to select it on its value option
<select id ="">
<option value="01" title=" 01 - Live animals"> 01 - Live animals</option>
</select>
I know that how to select drop down on its content i.e.
ie.select_list(:id, "DropDownList_Product").select("01 - Live animals")
actually I want to select drop down on its value 01,what should i have to do for that ?
Something like this should work:
ie.select_list(:id, "DropDownList_Product").select_value("01")
More information at http://rdoc.info/gems/watir-webdriver/Watir/Select#select_value-instance_method

Resources