Home > Software engineering >  click on affiliate link with selenium and python
click on affiliate link with selenium and python

Time:02-10

I have a problem grabbing an affiliate link that I receive a confirmation email. There is no button to click in email and just a full visible link:

https://website.com/en-am/niv/users/confirmation?confirmation_token=inxY3xs5t9vjaKWH4yt5

I used different find_elements in selenium but had no success

<a href="https://website.com/en-am/niv/users/confirmation?confirmation_token=inxY3xs5t9vjaKWH4yt5">https://website.com/en-am/niv/users/confirmation?confirmation_token=inxY3xs5t9vjaKWH4yt5</a>

Xpath: /html/body/div/p[2]/a

there is no ID,Class,Name,etc to use other type of find_elements. I also tried By.PARTIAL_LINK_TEXT and got error

Traceback (most recent call last):
  File "C:\Users\Acer\PycharmProjects\pythonProject2\new.py", line 17, in <module>
    link2 = driver.find_element(By.XPATH, "/html/body/div/p[2]/a").click()
  File "C:\Users\Acer\PycharmProjects\pythonProject2\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1244, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\Acer\PycharmProjects\pythonProject2\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Acer\PycharmProjects\pythonProject2\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/p[2]/a"}
  (Session info: chrome=98.0.4758.82)
Stacktrace:
Backtrace:
    Ordinal0 [0x01107AC3 2587331]
    Ordinal0 [0x0109ADD1 2141649]
    Ordinal0 [0x00F93BB8 1063864]
    Ordinal0 [0x00FC01CE 1245646]
    Ordinal0 [0x00FC03CB 1246155]
    Ordinal0 [0x00FEA612 1418770]
    Ordinal0 [0x00FD86D4 1345236]
    Ordinal0 [0x00FE8A0A 1411594]
    Ordinal0 [0x00FD84A6 1344678]
    Ordinal0 [0x00FB53F6 1201142]
    Ordinal0 [0x00FB62E6 1204966]
    GetHandleVerifier [0x012ADF22 1680738]
    GetHandleVerifier [0x01360DBC 2413564]
    GetHandleVerifier [0x0119D151 563089]
    GetHandleVerifier [0x0119BF13 558419]
    Ordinal0 [0x010A081E 2164766]
    Ordinal0 [0x010A5508 2184456]
    Ordinal0 [0x010A5650 2184784]
    Ordinal0 [0x010AF5BC 2225596]
    BaseThreadInitThunk [0x75E36739 25]
    RtlGetFullPathName_UEx [0x771F8E7F 1215]
    RtlGetFullPathName_UEx [0x771F8E4D 1165]

any suggestion?

CodePudding user response:

  •  Tags:  
  • Related