I'll try to explain again. I have to get the value Arizone but I'm only getting it via xpath. The element was mapped with: element :select_cad_state, "#uniform-id_state". I don't want to use xpath to get the value Arkansas, I want to use something like: select_state.send_keys(DATA[:cad_user][:_state]) ???..etc..etc..
I want to get the arizona value from the users.yml file and pass it as an argument in the front.
############ code page #####################
<div class="selector" id="uniform-id_state" style="width: 269px;"><span style="width: 259px; user-select: none;">Florida</span><select name="id_state" id="id_state" class="form-control" style="">
<option value="">-</option>
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="4">Arkansas</option></div>
################### my PageObjects #########################
class ScreenCadastro < SitePrism::Page
set_url 'http://automationpractice.com/index.php?controller=authentication&back=my-account'
element :input_cad_company, "#company"
element :input_cad_address, "#address1"
element :input_cad_city, "#city"
element :select_state, "#uniform-id_state" (my problem is here)
################ yaml file ##############
:cad_user:
:_password: 457226
:_company: SQATest
:_address: International Drive 678
:_city: Bradenton
:_state: Arizona
################## my env file ###################
DADOS = YAML.load(File.open(File.join(File.dirname(__FILE__) + "/massa/users.yml")))
input_cad_company.send_keys(DADOS[:cad_user][:_company])
input_cad_address.send_keys(DADOS[:cad_user][:_address])
input_cad_city.send_keys(DADOS[:cad_user][:_city])
find(:xpath,'/html/body/div/div[2]/div/div[3]/div/div/form/div[2]/p[7]/div/select/option[3]').click
You are asking about option value, but from all your code it looks like you actually want to select based on the string contents of the option element (not the value). As I posted in my answer to your previous question this should just be
select_state.select(DADOS[:cad_user][:_state])
If that is not working for you please provide the error message it's giving you.
Related
Brothers help me please. I need to validate the values of this combo, I tried it with a command I found here but I still haven't had success. The error I'm getting is: Reason:
Ambiguous match, found 7 elements matching visible option nil
----------------------------------------------
I noticed that the first value is white I don't know if this is the error but I tried to get it for a specific value and I couldn't do it either!!
My Code:
class Screen_Grupo_Intervencao < SitePrism::Page
include RSpec::Mocks::ExampleMethods::ExpectHost
include RSpec::Matchers
element :estrutura, :xpath, '//*[#name="_lyXWFMTGINID_ALAY"]'
all(screen_grupo_intervencao.estrutura select)1.should have_text('CADASTRO TÉCNICO D&C - DISTRIBUIÇÃO E COLETA ENGENHARIA GESTÃO DE PERDAS GSC COMERCIAL GSO OPERACIONAL')
<select style="padding-right:0px;width:100%;" class="f fA" onrealchange="return true;" onchange="setTooltip(this,'');realChangeListener(event);" id="686" name="_lyXWFMTGINID_ALAY" tabindex="151" evidence="">
<option title="" selected="" value="" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;"></option>
<option title="" value="61" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">CADASTRO TÉCNICO</option>
<option title="" value="41" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">D&C - DISTRIBUIÇÃO E COLETA</option>
<option title="" value="62" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">ENGENHARIA</option>
<option title="" value="63" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">GESTÃO DE PERDAS</option>
<option title="" value="1" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">GSC COMERCIAL</option>
<option title="" value="21" class="f fA" style="border:0px;border-radius:0px;font-size:1em;box-shadow:none;">GSO OPERACIONAL</option>
</select>
It would be a big help if you read the Stackoverflow instructions on inserting code into questions so it would format it correctly. Also the code you're showing somehow has a linked '1' stuck in the middle of it.
The error you're getting is because you have specified element :estrutura, :xpath, '//*[#name="_lyXWFMTGINID_ALAY"]' which means there should be only 1 of them. However on your page there are apparently 7 elements matching the xpath. Either make the selector more specific so it only matches one thing, or change it to elements :estrutura, :xpath, '//*[#name="_lyXWFMTGINID_ALAY"]' so it allows multiple elements to be found.
I would also suggest to stop using xpath when it's not necessary - elements :estrutura, '[name="_lyXWFMTGINID_ALAY"]'
Assuming you are meant to have multiple matching elements on the page and I'm reading you're code right then I think you'd be doing
screen_grupo_intervencao.estrutura[1].should have_text('CADASTRO TÉCNICO D&C - DISTRIBUIÇÃO E COLETA ENGENHARIA GESTÃO DE PERDAS GSC COMERCIAL GSO OPERACIONAL')
although that seems like a strange way to be testing.
I have the following source:
<p class="byline"><span class="attribute first">AUTHOR: </span>Stephen Butts<span class="attribute">DATE: </span><span class="monthText" style="margin-right:4px;">MAY</span>2015<span class="attribute">SUBJECT: </span>Options</p>
I want to use the XPath to grap the text/content of the AUTH: Stephen King. I've tried using the following but it doesn't work:
authors = tree.xpath('//span[#class="attribute first"]/text()', namespaces=ns)
How to do that?
You need a text of p, but not span. Try:
//p[#class="byline"]/text()[2]
or
//span[#class="attribute first"]/following-sibling::text()[1]
<div id="t_info" class="tab-pane fade active in tab">
<br><strong>Delivery</strong> <br>
<br><br><br><strong>Model Name</strong> : BP250
<br>
<br>Full HD up-scaling dramatically improves the resolution of any original content to Full HD.
<br>
<br><strong>Barcode</strong> : 8806087225921
<br>
<br><strong>Product Type</strong> : Blu-ray Player<br>
<br>Blu-Ray Disc <br>External <br></div>
I need xpath to capture the barcode value. Location of the barcode varies depending on the description.
I have tried //*[text()='Barcode'] . but i cant capture the value.
In your case you can use next XPath:
(//div[#id="t_info"]/text())[./preceding::strong[text()='Barcode']][1]
Please note that it is mauvais ton (bad manners)
I am attempting to capture a line of text for an automated WebDriver test to use it in a comparison later on. However, I cannot find an XPath that will work with WebDriver. I have used the text() function before to capture text that is not in a tag, but in this instance that is not working. Here is the HTML, note that this text will never be the same, so I cannot use contains or similar functions.
<div id="content" class="center ui-content" data-role="content" role="main">
<div data-iscroll="scroller">
<div class="ui-corner-all ui-controlgroup ui-controlgroup-vertical" data-role="controlgroup">
<a class="ui-btn ui-corner-top ui-btn-hover-c" style="text-align: left" data-role="button" onclick="onDocumentClicked(21228772, "document.php?loan=********&folderseq=0&itemnum=21228772&pageCount=3&imageTypeName=1003 Application - Final&firstInitial=&lastName=")" href="#" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="c">
<span class="ui-btn-inner ui-corner-top">
<span class="ui-btn-text">
<img class="checkMark checkMark21228772 notViewedCompletely" width="15" height="15" title="You have not yet viewed this document." src="../images/white_dot.gif"/>
1003 Application - Final. (Jan 11 2012 5:04PM)
</span>
</span>
</a>
In this example, the text I am attempting to capture is: 1003 Application - Final. (Jan 11 2012 5:04PM)
I have inspected the element with Firebug and I have tried the following XPaths with no success.
html/body/div[1]/div[2]/div/div/a[1]/span/span
html/body/div[1]/div[2]/div/div/a[1]/span/span/text()
The WebDriver test is being written in C#.
You can either use this
driver.FindElement(By.XPath(".//div[#id='content']/following-sibling::span[#class='ui-btn-text']")
or
var elem = driver.FindElement(By.Id("Content"));
string text = string.Empty;
if(elem!=null) {
var textElem = elem.FindElement(By.Xpath(".//following-sibling::span[#class='ui-btn-text']"));
if(textElem!=null) text = textElem.Text();
}
I was able to solve this issue by removing the span tags from the XPath.
GetText("html/body/div[3]/div[2]/div/div/a[1]", SelectorType.XPath);
python webdriver code looks something like
driver.find_element_by_xpath("//span[#class='ui-btn-text']").text
But locator may be not uniqe, because I can't see all the code
PS Try to never use locators like html/body/div[1]/div[2]/div/div/a[1]/span/span
Approach:
Find the CSS Selector from the Given DOM
Derived CSS:css=#content div.ui-controlgroup > a[onclick*='onDocumentClicked'] > span > span
Use the C# Library Method to get the Text.
Given the following HTML code snippet; after finding the link by ID, how would you select the checkbox in the same paragraph?
For example if I wanted to select the checkbox associated with the link with ID="inst_17901-1746-1747".
The order of the paragraphs in the DIV is not consistent between sessions so I cannot select it by index or ID of the checkbox.
<div id="inst-results">
<p>
<input id="inst-results0-check" type="checkbox">
<a class="ws-rendered" id="inst_17901-1746-1747" title="!!QA Data 2/DOOR FURNITURE/316 Stainless - Altro Range"><img src="http://yr-qa-svr2/Agility/ACMSImages?type=objectType&objectTypeID=32"> <span>!!QA Data 2/DOOR FURNITURE/316 Stainless - Altro Range</span></a>
</p>
<p>
<input id="inst-results1-check" type="checkbox"><a class="ws-rendered" id="inst_17882-1746-1747" title="!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range"><img src="http://yr-qa-svr2/Agility/ACMSImages?type=objectType&objectTypeID=32"> <span>!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range</span></a>
</p>
</div>
I figured out this solution working off the text of the link, but Zeljko solution is much better.
$browser.div(:id,"inst-results").ps.each { |para|
if para.link.text == "!!QA Data/DOOR FURNITURE/316 Stainless - Altro Range" then
para.checkbox.set
break
end
}
If there is only one checkbox in the paragraph with the link:
browser.link(:id => "inst_17901-1746-1747").parent.checkbox.set
Works with watir-webdriver, not sure if it would work with other Watir gems.