How can I make a variable out of an ID that is made after the item using the ID is created? - ruby

The problem I am having is in my testing I create an order which obtains an ID. This ID is different every-time.
Here is a picture of some sample code:
Thanks in advance to any help.
--Curtis

I can't tell exactly by the code provided, but wouldn't something this simple work
testID = #browser.div(:class, /screenlet-title-bar/).text
followed by some string manipulation to trim any unnecessary space or characters:
testID.gsub(" Purchase Order #", "") #Removes leading text

Have you tried XPath? Here is a tutorial on it.
testID = #b.link(:xpath, "//a[contains(#href, '/ordermgr/control/orderview?orderID')]/").text
The output should be the ID you need. If you have multiple ID's with the same xpath, it could be a problem, didn't try that.
Good Luck,
Dave

Related

How to use substring() with Import.io?

I'm having some issues with XPath and import.io and I hope you'll be able to help me. :)
The html code:
<a href="page.php?var=12345">
For the moment, I manage to extract the content of the href ( page.php?var=12345 ) with this:
./td[3]/a[1]/#href
Though, I would like to just collect: 12345
substring might be the solution but it does not seem to work on import.io as I use it...
substring(./td[3]/a[1]/#href,13)
Any ideas of what the problem is?
Thank's a lot in advance!
Try using this for the xpath: (Have the field selected as Text)
.//*[#class='oeil']/a/#href
Then use this for your regex:
([^=]*)$
This will get you the ISBN number you are looking for.
import.io only support functions in XPath when they return a node list
Your path expression is fine, but perhaps it should be
substring(./td[3]/a[1]/#href,14)
"Does not seem to work" is not a very clear description of what is wrong. Do you get error messages? Is the output wrong? Do you have any code surrounding the path expression you could show?
You can use substring, but using substring-after() would be even better.
substring-after(/a/#href,'=')
assuming as input the tiny snippet you have shown:
<a href="page.php?var=12345"/>
will select
12345
and taking into account the structure of your input
substring-after(./td[3]/a[1]/#href,'=')
A leading . in a path expression selects only immediate child td nodes of the current context node. I trust you know what you are doing.

Get the value of title using xPath

I am using the following but it does not get me the value of the title
//*[#id="843285"]/td[3]/a[#title]
Elche vs Osasuna
Can someone give me some guidance?
Few ways to find you the element directly, then use #title to get the title attribute. Note that your id is g843285, not 843285.
If it's always <a> tag (otherwiser use * but with lower performance)
//a[#id="g843285"]/#title
//a[contains(#id, "843285")]/#title
//a[contains(#href, "match/843285")]/#title
I assume you don't know the match teams (otherwise you won't need to find out title), so the following won't work, posting here just for references.
//a[text() = 'Elche vs Osasuna']/#title
"Find the element whose ID attribute equals "843285", and return the value of its title attribute"
//*[#id="843285"]/#title
You can do this if you're always dealing with a tags
//a[#id="g843285"]/#title
Otherwise do //*[#id="g843285"]/#title

Selenium IDE: Find correct Xpath element based on line

I'm using Selenium IDE and I have this sales information on a web page (example: http://s23.postimg.org/6vwlkqm57/image.jpg) that I need to store some info in variables. One of the info that I need to store is the Country letters (in this example, I need to store the letters LV in a variable).
I'm currently using this command:
Command: storeText || Target: //div[#id='content-main']/form[2]/table[4]/tbody/tr[9]/td[2] || Value: Country
The problem is: This Country information is not always on the 9th line (tr[9]) like in this example, sometimes it is in the 10th line.
My question is: Is there a way to, first find the correct line and then store the country letters?
HERE IS THE SOURCE HTML -- http://txtup.co/VPZR
Thanks in advance for any help!
This xpath should fix your problem -
//div[#id='content-main']/form[2]/table[4]//tr[contains(text(), 'Country')]/td[2]
I could make it work, thanks for everyone that helped me, I used this sintax:
//div[#id='content-main']/form[2]/table[4]/tbody/tr[td[1][contains(text(), 'Country')]]/td[2]

dynamic xpath expression

Good day, colleagues!
Tell me please, how to make a dynamic xpath-parsing:
for example, instead of writing
$domXPath->query('//*[(#id = "article-id-18")]');
-> write something like that
$domXPath->query('//*[(#id = "article-id-*")]');
, because in my case, the site's script generate (every time) a new id for block, that contains article's text?
So question, is above.
Try
$domXPath->query('//*[starts-with(#id, "article-id-")]');

XPath Find full HTML element ID from partial ID

I am looking to write an XPath query to return the full element ID from a partial ID that I have constructed. Does anyone know how I could do this? From the following HTML (I have cut this down to remove work specific content) I am looking to extract f41_txtResponse from putting f41_txt into my query.
<input id="f41_txtResponse" class="GTTextField BGLQSTextField2 txtResponse" value="asdasdadfgasdfg" name="f41_txtResponse" title="" tabindex="21"/>
Cheers
You can use contains to select the element:
//*[contains(#id, 'f41_txt')]
Thanks to Thomas Jung I have been able to figure this out. If I use:
//*[contains(./#id, 'f41_txt')]/#id
This will return just the ID I am looking for.
I suggest to not use numbers from Id , when you are composing xpath's using partial id. Those number reprezent DINAMIC elements. And dinamic elements change over the next deploys / releases in the System Under Test.The pourpose is to UNIQUE identify elements.
Using this may be a better option or something like this, yo got the idea:
//input[contains(#id, '_txtResponse')]/#id
It worked for me like below
//*[contains(./#id, 'f41_txt')]

Resources