1

I would like to write a python code where he clicks on the href link.

Screenshot of HTML: screenshot of HTML code

This is what I am currently having in Python, but it does not work.

tables = browser.find_elements_by_xpath('//*[@id="notice"]')

for table in tables:
     row = table.find_element_by_xpath('//tr[@class="Zebra"]//td//a[@href="https://enot.publicprocurement.be/enot-war/preViewNotice.do?noticeId=438868&saveSearchParams=true&pageSize=%31%32%35&d-446978-p=%31&"]').click()

This is the error message for row:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//tr[@class="Zebra"]//td//a[@href="https://enot.publicprocurement.be/enot-war/preViewNotice.do?noticeId=438868&saveSearchParams=true&pageSize=%31%32%35&d-446978-p=%31&"]"}

Could you please tell me what I am doing wrong?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

The desired element is a <a> element with the innerText as Universiteit Antwerpen-22004

To click on the desired element you can use either of the following locator strategies:

  • Using the href attribute:

    table.find_element_by_xpath('.//tr[@class="Zebra"]//td//a[starts-with(@href, "https://enot.publicprocurement.be/enot-war/preViewNotice.do?noticeId")]').click()
    
  • Using the innerText:

    table.find_element_by_xpath('.//tr[@class="Zebra"]//td//a[contains(., "Universiteit Antwerpen-22004")]').click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks, it works. However, I have another question. How can I refer to the output: "BME-BME - CSC 2022-008" This is the HTML code: [ BME-BME - CSC 2022-008 2022-513912 And this is my Python code (which works): total = soup.findAll('tr',{'class':'Zebra'}) print(total) in other words, how can I refer to the words after href ? thanks! – mathias5986 Apr 12 '22 at 18:38
  • @mathias5986 Glad to be able to help you. Feel free to raise a new question as per your new requirement. – undetected Selenium Apr 12 '22 at 19:17