Using regex while finding web element by id in Selenium java - selenium

I am trying to locate web elements using the element id. But the id of the same web element changing between
Driver.findElement(By.id("ItemDetailsCompView.**Edit**ViewUIElement_Field_Tab_2_Product_Materials"))
and
Driver.findElement(By.id(ItemDetailsCompView.**Display**ViewUIElement_Field_Tab_2_Product_Materials"))
This results in to an error when I have hard coded for one id and the other id occurs. Is there a way to create a string that searches for Edit / Display words in the id.
I am unable to use Xpath as my webpage is complex and consists of various nested tables.

You could try using a CSS selector (the syntax may be incorrect here, it's not clear what language you are using):
Driver.findElement(By.CssSelector([id*="ViewUIElement_Field_Tab_2_Product_Materials"]))
Even better if you can provide an element tag name on that.

Related

verifyText using *text* instead of verifyTextPresent (deprecated)

I'm kind of new to selenium IDE and automated test and I don't know much about programming languages. I have a question concerning verifyText command as verifyTextPresent is deprecated. If I put the target word/text in * * will it work as if I was using verifyTextPresent? Could waitForText work?
I am trying to verify that the search function of a website is working as expected. I search the word "client" and I want to verify that the word is present in the results.
clickAndWait css=div.cf-tooltip-text
type id=edit-global-search client
clickAndWait id=edit-submit-global-search
verifyText id=content-column *client*
This works, but in the Log I can not understand what it really does. Also if I try the word on its own "client" I get an error which I understand because it compares it to the text of the whole column. I also tried to put an irrelevant word between asterisks such as youwillnotfindthetext (just to make sure that everything between asterisks will pass the test) and there I had an error too.
So it seems to be working somehow but I want to ask some of you expert guys.
Thanks
If you put a * in starting and ending means it will look for the inner text containing in the specific element. If a text is present as you given in the script it will return a pass. If the text u specified in the script is not present, it will throw an error. That's what happens when you put youwillnotfindthetext in between the *.
Check this link Selenium: test if element contains some text

How to use Xpath extractor to extract mutiple fields using SOAP request in Jmeter?

I imported the webservice and did my first transaction passed. I see the request and reply xml
Now I want to extract ton of field values from the reply xml that I got and need to pass into Request xml.
For one field I know how to do that. I use Xpath Extractor to extract like this
//*[local-name()='Data']/text()`.
In the next action, I can just use as ${Data} which is working fine.
But I need to extract the text content from ton of fields that need to be passed into the next action.
How to do that using Xpath Extractor?
If your XPath query matches multiple /Data/text fields they will be caught as
TEXT_1=first match
TEXT_2=second match
etc.
If you need to combine results from different queries it can be done via pipe sign - | like
//*[local-name()='Data']/text()` | //*[local-name()='Something else']/text()
In this case result will go to the single variable.
Third option is using as many XPath extractors as needed.
See XPath Tutorial for general language reference and Using the XPath Extractor in JMeter guide for more tips and tricks.

How to check how many specific HTML elements are in a page using RSpec?

In Rails 4 feature spec, using RSpec 3 and Capybara, how do I assert if a certain number of specific tags are present in a page?
I tried:
expect(find('section.documents .document').count).to eq(2)
But it doesn't work, saying:
Ambiguous match, found 2 elements matching css "section.documents .document"
Also, is it a good idea/bad practice to test in a feature spec something so specific as the kind of tags and classes used in the view?
The problem with using find is that it is meant to return a single matching element. To find all matching elements, which can then be counted, you need to use all:
expect(all('section.documents .document').count).to eq(2)
However, this approach does not make use of Capybara's waiting/query methods. This means that if the elements are loaded asynchronously, the assertion may randomly fail. For example, all checks how many elements are present, the elements finish loading and then the assertion will fail because it compares 0 to 2. Instead, it would be better to make use of the :count option, which waits until the specified number of elements are present.
expect(all('section.documents .document', count: 2).count).to eq(2)
There is some redundancy in this code and the assertion message will be a bit strange (since there will be an exception rather than a test failure), so it would be better to also switch to using have_selector:
expect(page).to have_selector('section.documents .document', count: 2)

xpath filter while parent node changes name

I am trying to get the value of a node from third party source. Part of the Xmlstructure has a node whose name changes between, point and framedPoint. how do I get the latitude value?? here is part of the xml, their are many levels to the xml so have shown the relevant area.
here node is called point
<tpegpointLocation xsi:type="TPEGSimplePoint">
<point xsi:type="TPEGJunction">
<pointCoordinates>
<latitude>54.894825</latitude>
</pointCoordinates>
</point>
</tpegpointLocation>
here framedPoint
<tpegpointLocation xsi:type="TPEGSimplePoint">
<framedPoint xsi:type="TPEGJunction">
<pointCoordinates>
<latitude>54.894825</latitude>
</pointCoordinates>
</framedPoint>
</tpegpointLocation>
Thanks, for any help
You could use asterisk as a wildcard in your xpath
/tpegpointLocation/*/pointCoordinates/latitude
The following XPath would do the job:
//tpegpointLocation//pointCoordinates/latitude
Which means:
//tpegpointLocation search for all <tpegpointLocation> elements in the XML file
The second //pointCoordinates means search for all <pointCoordinates> elements below <tpegpointLocation> regardless which elements are between them (one or more or different names
/latitude means get the <latitude> element below <pointCoordinates>
Please note that using // scans whole XML file. If you are able to change //tpegpointLocation it would be better and faster.

Selenium IDE : How to use pattern checking for a dynamic id using XPath

In my website there is a recently uploaded image section.
in this section all recently uploaded images are displayed randomly
using firepath i traced the xpath of that location
//div[#id='udtkbdf50']/a/div[2]/div
so on each time page refresh this #id='udtkbdf50' value changes ,only one thing is common that is the value is always starting with u
so i want to use pattern matching technique [regular expression or Globbing Patterns ]
#id='udtkbdf50' for this value and rest of the path i.e /a/div[2]/div will remain same.
//div[contains(#id,'u')]/a/div[2]/div will work.
UPDATE:
//div[starts-with(#id,'u')]/a/div[2]/div will be more specific.
All d best.