Here is the structure I am dealing with:
<div class="class">
<h4 class="class2">
"Condition" </h4>
<div class = "click_class">Click_text </div>
</div>
I need to click on the element with class ="click_class"
only if the h4
has the text == "Condition"
.
I tried utilizing Xpath
:
.useXpath()
.click('//div[contains(@class, "class")]//h4[text()[contains(.,"Condition")]]')
This successfully finds the h4 element with text
as "Condition"
. Now, my goal is to locate the parent class
and proceed to click on click_class
.
.click('//div[contains(@class, "class")]//h4[text()[contains(.,"Condition")]]/parent::div[@class="class"]//div[text()="Click_text"]')
Unfortunately, this approach does not seem to work.
Is there a way to effectively click on an element based on a condition in the h4
text?