0

i am trying to download a pdf file('DOWNLOAD PRODUCT CATALOGUE') from the link steel. using python xpath to achieve this. but getting syntax errors. tried all permutations and combinations. the code what i have tried is as follows:

    import time
    from selenium import webdriver
    driver = webdriver.Chrome('c:/windows/chromedriver.exe')  # Optional argument, if not specified will search path.
    driver.get("https://sail.co.in/en/products/sail-structural-sections")
    time.sleep(5) # Let the user actually see something!
    elem =driver.find_element_by_xpath('//a[text()='Download Product Catalogue']//parent::div[@class='toppdf_brochure pdfbrochure']')
    elem.click()
    time.sleep(5) # Let the user actually see something!
    driver.quit()
1
  • You can't have a series of single quotes in a string or python will treat it as several strings. To begin troubleshooting try changing the two outermost ' in your xpath string to " Commented Nov 1, 2020 at 14:16

1 Answer 1

1

Try this xpath:

elem =driver.find_element_by_xpath("//*[contains(text(), 'Download Product Catalogue')]")

Full code:

import time
from selenium import webdriver
driver = webdriver.Chrome('c:/windows/chromedriver.exe')  # Optional argument, if not specified will search path.
driver.get("https://sail.co.in/en/products/sail-structural-sections")
time.sleep(5) # Let the user actually see something!
elem =driver.find_element_by_xpath("//*[contains(text(), 'Download Product Catalogue')]")
elem.click()
time.sleep(5) # Let the user actually see something!
driver.quit()

Browser Screenshot:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.