Question

How to capture a row in a website using Xpath?

  • 2 January 2022
  • 8 replies
  • 13 views

Userlevel 2
Badge +8

There is a long links(many rows on the website), and they are like this:

each row is like this, starts with date, and ends with "</a>"

 1/1/2022 6:58 AM     2402 <a href="/Carrier/PC_565367379/HOT_DAILY/HOT_20.3_20211231.zip">HOT_20.3_20211231.zip</a>

<br>

 1/2/2022 6:53 AM     775 <a href="/Carrier/PC_565367379/HOT_DAILY/HOT_20.3_20220101.zip">HOT_20.3_20220101.zip</a>

 

My aim is to get the row which has today's date information, and paste it into excel or text file, and click on the link for downloading.

 

How could I get the today's row information?

 

//a[@href='/Carrier/PC_565367379/HOT_DAILY/HOT_20.3_$Year$$Month$$Day-1$.zip'] may work for the link.

 

But i want to capture whole data, starting from the date as 1/2/2022 and ending with .zip

 

All the links are inside <pre> element

 

Since I couldnt find the Html element to look for 1/2/2022 date, i couldnt do this

 

Do you have any idea for this?

Thank you


8 replies

Userlevel 3
Badge +7

Hi @Semih Öztürk​ ,

 

Could you try converting the date to string using the format yyyyMMdd and passing that into the xpath?

 

image 

//a[contains(text(),'strDate')]

 

Kind Regards,

Ashwin A.K

Userlevel 3
Badge +7

Also, the attribute must have '@' prefixed to it.

 

//a[@href='/Carrier/PC_565367379/HOT_DAILY/HOT_20.3_20150215.zip']

 

Kind Regards,

Ashwin A.K

Userlevel 2
Badge +8

Hi @Ashwin A.K​ 

Yeah i got the idea, it just should select the link which has that date i write there.

it didnt capture in last days either.

 

i tried this but it didnt work either, //a[href='/Carrier/PC_565367379/HOT_DAILY/HOT_20.3_20150215.zip'}

Userlevel 3
Badge +7

Hi @Semih Öztürk​ ,

 

The closing bracket should be square as well, could you make that change and try once more?

If that doesn't work either, then you have to find an anchor, maybe a title and them travel ahead using child or following-sibling.

 

Here is a post for further reading on the subject.

 

Kind Regards,

Ashwin A.K

Userlevel 2
Badge +8

Hi @Ashwin A.K​ 

I tried that adding @ prefix, still couldnt find

i have tried //*[text()[contains(.,'20150215')]] too , still not captured.

 

I am gonna read the post, thank you

 

Userlevel 3
Badge +7

Hi @Semih Öztürk​ ,

 

Have you tried with any of the latest dates?

//*[contains(text(),'20220101')]

Or

//a[Contains(@href,'20220101')] 

Its kind of hard to say since I don't have direct access to the instance, but I think you got the basic idea right?

The dates are what we will use to target the line items.

 

Kind Regards,

Ashwin A.K

Userlevel 2
Badge +8

Hi @Ashwin A.K​ 

I tried this just to see if it shows me the output //*[contains(text(),'20141203')]

but it didnt capture any line.

Userlevel 2
Badge +8

Hello @Ashwin A.K​ 

I am expected to click on the last link everyday. The last link's domxpath for today is

/html/body/pre[1]/a[2624], this domxpath helped me to click correctly.

 

But this will be dynamic. So ill need to click on the link which 2625 tomorrow.

 

I hold this value in an excel file, and store this into a variable, changed to number from string, and i updated the domxpath as

/html/body/pre[1]/a[$recorderIndexValueNum$]

but it didnt accept this,

why would it be

Reply