Prozorov
Prozorov

Reputation: 159

How to change value of xpath dynamically

I have the following element, and i would like to click on each tab and check if value is present inside the input field, i would like to avoid creating each WebElement for each Language

enter image description here

enter image description here

Could somebody kindly let me know how to go about it. Otherwise i end up instatiating element for each language and performing a click and checking the text area so if xpath or css can be manipulated it would be awesome

@FindBy(xpath = "//div[contains(text(),'dynamically changeable language')]

Thank you so much in advance guys.

Upvotes: 1

Views: 1657

Answers (2)

JaSON
JaSON

Reputation: 4869

You can use class name attribute to select all elements as list and then iterate over it:

"//div[starts-with(@class,'tabbedTextarea_TabButton')]"

Upvotes: 0

Tejashree Kutte
Tejashree Kutte

Reputation: 104

You can try iterating over the elements using for loop.

E.g.

List links =@FindAll(xpath = "//div[contains(text(),'dynamically changeable language'));

for(int i =0; i<=links.length; i++){
@Find(xpath = "(//div[contains(text(),'dynamically changeable language)[i]'));

//hear click and check the text
}

You can also use for each loop, if you want to avoid using the above for loop, but it might give you stale element error.

Upvotes: 1

Related Questions