I would like to write a python code where he clicks on the href link.
Screenshot of HTML:
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[@]//td//a[@href="https://enot.publicprocurement.be/enot-war/preViewNotice.do?noticeId=438868&saveSearchParams=true&pageSize=125&d-446978-p=1&"]').click()
This is the error message for row:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//tr[@]//td//a[@href="https://enot.publicprocurement.be/enot-war/preViewNotice.do?noticeId=438868&saveSearchParams=true&pageSize=125&d-446978-p=1&"]"}
Could you please tell me what I am doing wrong?
CodePudding user response:
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[@]//td//a[starts-with(@href, "https://enot.publicprocurement.be/enot-war/preViewNotice.do?noticeId")]').click()
Using the innerText:
table.find_element_by_xpath('.//tr[@]//td//a[contains(., "Universiteit Antwerpen-22004")]').click()