0

I'm trying to automate building a database of photos of this website : mcmaster it is using ajax.

but it's impossible to click on its first-page elements I have tried these codes :

driver.find_element_by_id("//span[@class='s7']").click()

or

driver.find_element_by_id("//a[span/@class='s7']").click()

or

driver.find_elements_by_tag_name("a")[5].click()

but it says element not intractable and there is nothing else to locate the page elements with.

I just can't understand if a a tag is not clickable what is clickable?

Ch3steR
  • 20,090
  • 4
  • 28
  • 58

1 Answers1

1

There are 39 elements on the webpage https://www.mcmaster.com/screws which can be identified by using the Locator Strategy:

driver.find_element_by_id("//span[@class='s7']")

But all of those elements are not visible / interactable. So as an alternative to identify the elements within the Fasteners section as they appear within the webpage and you can use the following based Locator Strategy:

  • Code Block:

    driver.get('https://www.mcmaster.com/')
    print([my_elem.text for my_elem in WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.XPATH, "//h2[normalize-space()='Fasteners']//following::ul[1]//li/a")))])
    
  • Console Output:

    ['Screws & Bolts', 'Threaded Rods & Studs', 'Eyebolts', 'U-Bolts', 'Nuts', 'Washers', 'Shims', 'Helical & Threaded Inserts', 'Spacers & Standoffs', 'Pins', 'Anchors', 'Nails', 'Nailers', 'Rivets', 'Rivet Tools', 'Staples', 'Staplers', 'Key Stock', 'Retaining Rings', 'Cable Ties', 'Lanyards', 'Magnets']
    

To click on the first element you can use the following based Locator Strategy:

driver.get('https://www.mcmaster.com/')
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//h2[normalize-space()='Fasteners']//following::ul[1]/li/a"))).click()   
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • thank you it works but I have a new problem in this site , click on screws on the fist page . then you will have a page with a list . if I right click on each one and open it in a new page , there will be a A tag in the html of the page and in the new opened tab there will be a address in the address-bar like : https://www.mcmaster.com/screws/=ae03acbf4f3841a793074ddbe97b5552k7tf9wh3 . I'm trying to collect those addresses . please help me . A tags doesn't exist until I click on the items :( – طاها سمر Mar 15 '20 at 19:20
  • please answer my question here – طاها سمر Mar 15 '20 at 20:38
  • this one up here in comments – طاها سمر Mar 15 '20 at 20:38