I got a table with 5 columns: "Name", "Age" Gender" Occupation" and "Salary":
xpath of "Name" column header:
//button[@class='sort-header-btn' and text()='Name']
And its field xpath is:
//div[@row-id='" DynamicName "']//following-sibling::div[@cold-id='Name']
I need to verify that "Dynamic Name" should not be exceed 10 String characters.
CodePudding user response:
Here you passing the DynamicName
string as a parameter to locate the desired element.
If you want to verify this string name you can do that before passing this parameter to Selenium method.
This can be done as well after passing the parameter to Selenium method, but anyway since you passing this string as a parameter you always have it, so you can check this string length easily since you already have it value.
CodePudding user response:
Having read your question and the comment, I think what you are looking for is not the length of "Dynamic Name", but the length of the field's value of below xPath
//div[@row-id='" DynamicName "']//following-sibling::div[@cold-id='Name']
If that is the case, then just use the below code to print the length of the string of web element in this xPath
System.out.println(driver.findElement(By.xpath("//div[@row-id='" DynamicName "']//following-sibling::div[@cold-id='Name']")).getText().length());