[Python] Selenium - Unable to find element using xpath

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I am writing a webscraper in python to get the current patch version for a list of products. I am trying to locate the text by XPATH, but I am being told that no such element exists. I have tried both an implicit and explicit wait up to 60 seconds, but still have not had any success. I see that there is an iframe on the page, but the text I am trying to access is not in that iframe, so I don't think it's relevant. Either way, I tried to switch to that iframe and find the element in there as a test, but was not successful.

    This is the page I am trying to scrape

    I am simply trying to get the newest version number. I have the XPATH as: /html[1]/body[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[5]/div[1]/div[1]/div[1]/div[1]/table[1]/tbody[1]/tr[2]/td[2]/span[1]

    This is the code I am using

    url = "https://compatibility.rockwellautomation.com/Pages/ProductReplacement.aspx?crumb=101&restore=1&vid=53216"
    RA_XPATH = "/html[1]/body[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[5]/div[1]/div[1]/div[1]/div[1]/table[1]/tbody[1]/tr[2]/td[2]/span[1]"
    driver.get(url)
    element = WebDriverWait(driver, 60).until(EC.presence_of_all_elements_located((By.XPATH, RA_XPATH)))
    version = driver.find_element(By.XPATH, RA_XPATH)


    I am able to locate it with the Rel XPath, but I would like to use the Abs XPath because it looks like it is the same across multiple products. For Example on this page, the Abs XPath is the same as the other page, but the Rel Xpath is different

    I am completely stumped.
    I am relatively new to all of this, so I thank you for your patience!

    Continue reading...

Compartilhe esta Página