I got problem such as :
id="tabscontent:tabView:BWconent_0:j_idt670"
After exceute
id changed = "tabscontent:tabView:BWconent_0:j_idt682"
670 change 682
Everyone know how to make : contains() or starts-with() or ends-with()
Please to help me
Thank you so much
P/s : I mean using xpath id for Katalon Testcase
Assuming that the beginning part of the id is static you can use starts-with() like this:
//*[starts-with(#id, 'tabscontent:tabView:BWconent_0:treeLeft_0:1:j_idt')]
The above XPath will return elements with id attribute value starts with "tabscontent:tabView:BWconent_0:treeLeft_0:1:j_idt"
Use this
TestObject myObject = new TestObject().addProperty('css', ConditionType.EQUALS, 'a[id^="tabscontent:tabView:BWconent_0"]')
The ^="some text" denotes "starts-with" for css selectors.
You will need to import TestObject and ConditionType classes. You can just press Ctrl+Shift+O in script mode and Katalon will do the rest.
Related
I have the following XPath :
//table[#class='ui-jqgrid-htable']/thead/tr/th//text()
And I'm trying to get the text from it with the following command :
String LabelName = driver.findElement(By.xpath("//table[#class='ui-jqgrid htable']/thead/tr/th//text()")).getText()
But it's not printing text, the result is blank. Could you help me please ?
The text() in your xpath does not qualify as an element. Your element ends at //table[#class='ui-jqgrid-htable']/thead/tr/th. Try using getText() for this XPath.
Also, a table would have many headers. Using findElement will only return the first one.
If you want to get all headers use
driver.findElements(By.xpath("//table[#class='ui-jqgrid-htable']/thead/tr/th"))
and loop through the list to getText of individual element.
List <WebElement> elt2=driver.findElements(By.xpath("//*[contains#className,'textInputContainers']"));
Also tried the version below:
List< WebElement > elt2 = driver.findElements(By.xpath("//*[contains#id,'txt']"));
contains() is a function and so must have () around its arguments.
So change
//*[contains#className,'textInputContainers']
to
//*[contains(#className,'textInputContainers')]
Note: A more robust way to test for a class name within a #class attribute can be found here: Xpath: Find element with class that contains spaces
I've been through the xpath tutorials and checked many other posts, hence I'm not sure what I'm missing. I'm simply trying to find the following element by xpath:
<input class="t-TextBox" type="email" test-id="test-username"/>
I've tried many things, such as:
element = findElement(By.xpath("//[#test-id='test-username']"));
The error is Expression is not a legal expression.
I'm using Firefox on MacBook
Any suggestion would be greatly appreciated.
element = findElement(By.xpath("//*[#test-id='test-username']"));
element = findElement(By.xpath("//input[#test-id='test-username']"));
(*) - means any tag name.
You should add the tag name in the xpath, like:
element = findElement(By.xpath("//input[#test-id='test-username']");
your syntax is completely wrong....you need to give findelement to the driver
i.e your code will be :
WebDriver driver = new FirefoxDriver();
WebeElement element ;
element = driver.findElement(By.xpath("//[#test-id='test-username']");
// your xpath is: "//[#test-id='test-username']"
i suggest try this :"//*[#test-id='test-username']"
You missed the closing parenthesis at the end:
element = findElement(By.xpath("//[#test-id='test-username']"));
Just need to add * at the beginning of xpath and closing bracket at last.
element = findElement(By.xpath("//*[#test-id='test-username']"));
You can use contains too:
element = findElement(By.xpath("//input[contains (#test-id,"test-username")]");
You haven't specified what kind of html element you are trying to do an absolute xpath search on. In your case, it's the input element.
Try this:
element = findElement(By.xpath("//input[#class='t-TextBox' and #type='email' and #test-
id='test-username']");
Correct Xpath syntax is like:
//tagname[#value='name']
So you should write something like this:
findElement(By.xpath("//input[#test-id='test-username']"));
I am trying to add a variable to an xpath but to no avail
This works below for java
assertTrue("Failed", verifyElementPresent("//*[#class='StdLJText' and contains(.,'2 Employees selected')]"));
but when I add a variable , like below it does not
String CountEmp1="2";
assertTrue("Failed", verifyElementPresent("//*[#class='StdLJText' and contains(.,CountEmp1+'Employees selected')]"));
You need to put CountEmp1 as a string addition in the main verifyElePresent func i.e verifyElementPresent("//*[#class='StdLJText' and contains(.,"+CountEmp1+"Employees selected')]"));
Note the replacement of "+CountEmp1+" at contains(.,CountEmp1+'
With your xpath the verifyElementPresent method basically looks for //*[#class='StdLJText' and contains(.,CountEmp1+'Employees selected')] where countEmp1 is taken as string value and not something that needs to be concatenadated.
I am trying to click an element that changes per each order like so
edit_div_123
edit_div_124
edit_div_xxx
xxx = any three numbers
I have tried using regex like so:
#driver.find_element(:css, "#edit_order_#{\d*} > div.submit > button[name=\"commit\"]").click
#driver.find_element(:xpath, "//*[(#id = "edit_order_#{\d*}")]//button").click
Is this possible? Any other ways of doing this?
You cannot use Regexp, like the other answers have indicated.
Instead, you can use a nifty CSS Selector trick:
#driver.find_element(:css, "[id^=\"edit_order_\"] > div.submit > button[name=\"commit\"]").click
Using:
^= indicates to find the element with the value beginning with your criteria.
*= says the criteria should be found anywhere within the element's value
$= indicates to find the element with with your criteria at the end of the value.
~= allows you to find the element based on a single criteria when the actual value has multiple space-seperated list of values.
Take a look at http://net.tutsplus.com/tutorials/html-css-techniques/the-30-css-selectors-you-must-memorize/ for some more info on other neat CSS tricks you should add to your utility belt!
You have no provided any html fragment that you are working on. Hence my answer is just based on the limited inputs provided your question.
I don't think WebDriver APIs support regex for locating elements. However, you can achieve what you want using just plain XPath as follows:
//*[starts-with(#id, 'edit_div_')]//button
Explanation: Above xpath will try to search all <button> nodes present under all elements whose id attribute starts with string edit_div_
In short, you can use starts-with() xpath function in order to match element with id format as edit_div_ followed by any number of characters
No, you can not.
But you should do something like this:
function hasClass(element, className) {
var re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
return re.test(element.className);
}
This worked for me
#driver.find_element(:xpath, "//a[contains(#href, 'person')]").click