Iam unable to get the text value present under strong tag, as after a particular execution or task completion in browser tag gets change.
HTML Code before execution or task completion:
<div>
<strong>heizil</strong>:
<label id="check_label">
<em style="padding: 1px; box-shadow: rgb(229, 229, 229) 1px 1px; border-radius: 3px; background-color: rgb(0, 191, 255); color: rgb(0, 0, 0); font-style: inherit;" match="test" loopnumber="385144110">Test</em> device testing - Android testing
</label>
HTML code after execution or task completion :
<a id="id_1008326" >
<strong>heizil</strong> :
<label id="check_label"> "device testing - Android testing"
</label>
using the following code line :
System.out.println(driver.findElement(By.xpath("//a[@class='activity'][contains(.,'Android testing')]/strong")).getText());
I'm getting desired result (heizil),but if i try to get strong tag text value before HTML execution or task completion iam getting no element exception.
Is there anyway we can print (heizil) text under strong tag using ' device testing - Android testing ' as this is the only text constant, irrespective of after execution or before execution.
Note : observed <div>
tag before completion of task and after completion of task it changes to another HTML code, could you please help me getting textvalue inside strong tag using text ' device testing - Android testing '
CodePudding user response:
Try with this xpath:
//label[@id='check_label']/preceding-sibling::strong
Or xpath with utilize contains
function:
//label[contains(.,'Android testing')]/preceding-sibling::strong