Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99413

how do i write if..else statement using xpath

$
0
0

How do i write if--else statement using xpath.

//div[@class='slick-viewport']/div/div --It gives me 5 following div tags.

<div class="custom-tooltip slick-cell l1 r1" xpath="1">
    <svg width="100%" height="25" version="1.1" id="SVG_b244db8a-9345-4d57-a865-115c447e4b33" data-ispopupdisplayallowed="true" data-measureid="484" data-is-pcp-user="false" data-is-po-user="true" onclick="openEngagementWithEcosystemSummary('SVG_b244db8a-9345-4d57-a865-115c447e4b33')" xmlns="http://www.w3.org/2000/svg">
    <g></g>
    <text x="10" y="17" fill="black" style="font-weight: bolder; font-size: 12px;" id="PopUp_b244db8a-9345-4d57-a865-115c447e4b33"></text>
    </svg>
</div>
<div class="custom-tooltip slick-cell l1 r1" xpath="2">
    <svg width="100%" height="25" version="1.1" id="SVG_2264e127-682c-426f-a9fe-b3963363f9b3" data-ispopupdisplayallowed="true" data-measureid="486" data-is-pcp-user="false" data-is-po-user="true" onclick="openEPSDTCompletionRateSummary('SVG_2264e127-682c-426f-a9fe-b3963363f9b3')" xmlns="http://www.w3.org/2000/svg">
    <g></g>
    <text x="10" y="17" fill="black" style="font-weight: bolder; font-size: 12px;" id="PopUp_f32ad3d5-e795-4752-9df4-814f99d265b7">
    51% </text>
    </svg>
</div>
<div class="custom-tooltip slick-cell l1 r1" xpath="2">
    <svg width="100%" height="25" version="1.1" id="SVG_2264e127-682c-426f-a9fe-b3963363f9b3" data-ispopupdisplayallowed="true" data-measureid="486" data-is-pcp-user="false" data-is-po-user="true" onclick="openEPSDTCompletionRateSummary('SVG_2264e127-682c-426f-a9fe-b3963363f9b3')" xmlns="http://www.w3.org/2000/svg">
    <g></g>
    <text x="10" y="17" fill="black" style="font-weight: bolder; font-size: 12px;" id="PopUp_f32ad3d5-e795-4752-9df4-814f99d265b7">
    31% </text>
    </svg>
</div>
    <div class="custom-tooltip slick-cell l1 r1" xpath="3">
    <svg width="100%" height="25" version="1.1" id="SVG_cd847418-1c52-465a-a473-1e3ae2a0b979" data-ispopupdisplayallowed="false" data-measureid="485" data-is-pcp-user="false" data-is-po-user="true" xmlns="http://www.w3.org/2000/svg">
    <g></g>
    <text x="10" y="17" fill="black" style="font-weight: bolder; font-size: 12px;" id="PopUp_cd847418-1c52-465a-a473-1e3ae2a0b979">
    Available 
    </text>
    </svg>
</div>
    <div class="custom-tooltip slick-cell l1 r1" xpath="4">
    <svg width="100%" height="25" version="1.1" id="SVG_856b33a6-b361-4020-a01c-fbccb9d171de" data-ispopupdisplayallowed="false" data-measureid="500" data-is-pcp-user="false" data-is-po-user="true" xmlns="http://www.w3.org/2000/svg">
    <text x="10" y="17" fill="black" style="font-weight: bolder; font-size: 12px;" id="PopUp_856b33a6-b361-4020-a01c-fbccb9d171de">
    Available 
    </text>
    </svg>
</div>

In Short,

//div[@class='@class='slick-viewport'']//div[2]//*[name()='svg' and @data-ispopupdisplayallowed='true']

--Giving 3 elements(rows)

Second and third row contains the tag text which contains value/string "51%" and 31% while first row does not contain any value for text tag..

//div[@class='@class='slick-viewport']//div[2]//*[name()='svg' and @data-ispopupdisplayallowed='false'] ---Giving 2 elements(rows)

My for loop will execute 5 times(totalNoOfDivs.size())

Need a help to write it down if...else statement for above 3 conditions and will be part of for loop.

1st condition needed for ----Not contain any text the text tag.(@data-ispopupdisplayallowed='true')

2nd condition needed for -----contain the text such as 51%, 31% (@data-ispopupdisplayallowed='true')

3rd condition needed for -- Just to fetch the text "Available"(@data-ispopupdisplayallowed='false')

In short all 3 conditions perform different operations after clicking on row so need to put in for with if...else statement. Any help will be appreciated.....


Viewing all articles
Browse latest Browse all 99413

Trending Articles