1

/html[1]/body[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[1]/div[1]/div[4]/div[1]/div[1]/div[5]/div[1]/div[*]/div[2] --

this XPath giving me 4 div tag, i have expanded here last 2 tags. These are basically 4 rows and that i have to click one after other if row contains value it will get popup and value will be print on console else what ever written on row that have to be printed on console.

Here on 2nd and 4th row(div) the text is "Please wait.... " .

And 3rd div tag is contain 91% which i am able fetch with //*[name()='svg']//*[name()='g'][1]//*[name()='text'] and printed on console. But finding difficulty to fetch the text "Please Wait..." . from the div tag.

Here is 4 div tag code

<div class="custom- slick-cell l1 r1" style="" xpath="1"></div>
<div class="custom- slick-cell l1 r1" style="" xpath="2"></div>
<div class="custom- slick-cell l1 r1 active selected" style="" xpath="3">
   <svg width="100%" height="25" version="1.1" id="SVG_c0784e89-a155-4a07-b7d1-8236510dd78c" data-ispopupdisplayallowed="true" data-measureid="486" data-is-pcp-user="false" data-is-po-user="true" onclick="openEPSDTCompletionRateSummary('SVG_c0784e89-a155-4a07-b7d1-8236510dd78c')" 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_c0784e89-a155-4a07-b7d1-8236510dd78c">
         91%
      </text>
      <g></g>
   </svg>
</div>
<div class="custom- slick-cell l1 r1" xpath="4">
   <svg width="100%" height="25" version="1.1" id="SVG_f4f7f3fb-b09d-4c26-ac2f-81e01172416f" data-ispopupdisplayallowed="false" data-measureid="500" 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_f4f7f3fb-b09d-4c26-ac2f-81e01172416f">
         Please wait.... 
      </text>
      <g></g>
   </svg>
</div>
CEH
  • 5,701
  • 2
  • 16
  • 40
Appi
  • 95
  • 1
  • 10
  • I am not sure how this you xpath `//*[name()='svg']//*[name()='g'][1]//*[name()='text']` relevant to your html snippet because you have not `` groups which are not empty (at least in the code you have provided) – Alexey R. Nov 15 '19 at 18:06
  • This xpath should identify the element `Please wait....` and Xpath is `//div[@class='custom- slick-cell l1 r1']//*[name()='svg']//*[name()='text'] ` – KunduK Nov 15 '19 at 18:11

3 Answers3

0

Try this below xpath options.

//div[@class='custom- slick-cell l1 r1']//*[name()='svg']//*[name()='text'] [contains(.,'Please')]

OR

//div[@class='custom- slick-cell l1 r1']//*[name()='svg']//*[name()='text']

OR

//div[contains(@class,'custom- slick-cell')]//*[name()='svg']//*[name()='text'] [contains(.,'Please')]
KunduK
  • 32,888
  • 5
  • 17
  • 41
  • All above mentioned 3 options has given '0' element. Didn't work. – Appi Nov 15 '19 at 18:24
  • Strange.Please provide some wait before interacting the element.Should work based on the DOM you have provided. – KunduK Nov 15 '19 at 18:27
  • I am checking the code with Chropath and on console using $x(" "); – Appi Nov 15 '19 at 18:31
  • How are you enabling the please wait... in actual use case?to click on some button or how? – KunduK Nov 15 '19 at 18:39
  • This text just displayed on row, just wanted to fetch it same as on one row it displayed 91% which i am able to fetch as mentioned in my question. – Appi Nov 15 '19 at 18:42
0

Can you please try below xpath :

//div[@custom- slick-cell l1 r1']//*[local-name()='svg']//*[local-name()='g']//*[name()='text'][1]

I can understand you cant provide url but please find below example of svg element.

//span[@class='float-left header-icon-left']//*[local-name()='svg']//*[local-name()='g']//*[name()='path'][1]

Url: https://stackoverflow.com/questions/14592213/selenium-webdriver-clicking-on-elements-within-an-svg-using-xpath

enter image description here

SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/202441/discussion-on-answer-by-rock-not-able-fetch-the-text-from-svg-tag). – Samuel Liew Nov 15 '19 at 20:33
0

you can use this xpath

xpath = driver.find_elements_by_xpath('//div[@class='custom- slick-cell l1 r1']//*[name()='svg']//*[name()='text'] [contains(.,'Please')]')
Hamza Lachi
  • 1,046
  • 7
  • 25
  • Please check my this doubt too. https://stackoverflow.com/questions/58879517/for-loop-fetching-all-values-except-one-value – Appi Nov 15 '19 at 18:35