skip to Main Content
<a href="/r/androidapps/comments/13olal1/what_happens_to_photos_resized_in_samsung_builtin/">
  <div class="_1AKeAGcglmBjK1SUUXNFti _1-SZ3VwLjbFwTzaZvU8FBX _1FT0e6kh1BBb_oALAMW_l7 _1yBpz1MEPxxYTxjlEilGtB" data-testid="post-title" style="--posttitletextcolor:#222222">
    <h3 class="_eYtD2XCVieq6emjKBH3m">what happens to photos resized in Samsung built-in gallery app</h3>   </div>
</a>

I want "/r/androidapps/comments/13olal1/what_happens_to_photos_resized_in_samsung_builtin/" in the "a" tag. How do I use selenium to get the url as a string?
driver.find_element(By.LINK_TEXT, WHAT GOES HERE?)

2

Answers


  1. You should be able to find that information using:

    element_link = driver.find_element(By.XPATH, '//div[@data-testid="post-title"]/ancestor::a').get_attribute('href')
    

    Selenium documentation can be found here.

    Login or Signup to reply.
  2. The code using LINK_TEXT should be:

    driver.find_element(By.LINK_TEXT, "what happens to photos resized in Samsung built-in gallery app")
    

    If you want to print the href attribute and check, try the below code:

    element = driver.find_element(By.LINK_TEXT, "what happens to photos resized in Samsung built-in gallery app")
    print(element.get_attribute('href'))
    

    It should print the below in the console:

    /r/androidapps/comments/13olal1/what_happens_to_photos_resized_in_samsung_builtin/
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search