Python Forum
Selenium: Click on a Link Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium: Click on a Link Error
#1
hey guys,

im currently trying to acces a link via Selenium. The Link named 'Ansehen' exists X amount of times, so the only difference in the source code between them is the string in the brackets of its onclick

<a href="#" onclick="doRetrievePnr('C2YK79')" id="viewPnr">Ansehen</a>

The String in the Brackets (('C2YK79')) is the only difference between all the Links with the name "Ansehen".

i tried all the methods with Selenium to click on that but i am failing. I think it has something to do with the string in the brackets?

Heres my Function:
def log_in_and_OPTIONALISIERT():
    driver = webdriver.Chrome(path)
    driver.maximize_window()
    driver.get(url)

    driver.find_element_by_name("agencyCode").send_keys(agentur_code)
    driver.find_element_by_name("agencyId").send_keys(Agent_ID)
    driver.find_element_by_name("password").send_keys(Passwort)
    driver.find_element_by_xpath('//button[@type="button"]').click()
    #driver.find_element_by_xpath('//button[@onclick="togglesidebar(event)"]').click()
    driver.find_element_by_link_text("PRRN Buchungssuche").click()
    
    element = driver.find_element_by_id("bl_payment_status_chosen").click()
    driver.find_element_by_xpath('//li[@data-option-array-index="2"]').click()
    driver.find_element_by_id("proceed").click()
    driver.implicitly_wait(5)

    # PROBLEM STARTS HERE

    # FIRST TRY
    driver.find_element_by_link_text("doRetrievePnr('C2YK79')").click()
  
    # SECOND TRY
    driver.find_element_by_xpath("//a[contains(@onclick,'doRetrievePnr('C2YK79')']").click()
source code!!!: [Image: Gp68fh7] (if doesnt work: https://ibb.co/Gp68fh7 )

if doesnt work again:
1. link <td class="text-right">
          <a href="#" onclick="doRetrievePnr('C2YK79')" id="viewPnr">Ansehen</a></td>

2. link <td class="text-right">
          <a href="#" onclick="doRetrievePnr('U3DD99')" id="viewPnr">Ansehen</a></td>   
Following Error occurs: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"doRetrievePnr('C2YK79')"


Thanks Heart Heart
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  selenium. xpath error 3lnyn0 1 1,550 Dec-26-2022, 02:49 PM
Last Post: snippsat
  I can't open a link with Selenium in Python jao 0 1,413 Jan-30-2022, 04:21 AM
Last Post: jao
  Selenium Chrome error Leo_Red 2 1,878 Nov-05-2020, 02:40 PM
Last Post: Leo_Red

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020