Bottom Page

Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Click Element if displayed using Selenium and Python
Hi guys, I'm coding a script in which, when a button is clicked, sometimes a div appears and others it doesn't.
I'm trying to handle this exception using the following code

for i, j  in zip(range(160), tag):

    if i%10  == 0:
      url_to_search = "" + j + "/"
      element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".v1Nh3.kIKUG._bz0w"))) #Click prima foto

      element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".oW_lN._0mzm-.sqdOP.yWX7d"))) #Click follow
      checkFo = driver.find_element_by_class_name(".aOOlW.HoLwm")

      if checkFo.is_displayed():

          element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".HBoOv.coreSpriteRightPaginationArrow")))
 #Click arrow

          element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".oW_lN._0mzm-.sqdOP.yWX7d")))
 #Click follow
          if checkFo.is_displayed():
              element = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".HBoOv.coreSpriteRightPaginationArrow")))
     #Click arrow
But it doesn't work! The shell gives me this error:
Unable to locate element: {"method":"class name","selector":".aOOlW.HoLwm"}
Can anybody help me?
You can try waiting to make sure that element is up before, or try an ID instead. You wait for the others, but are not waiting for the one that is giving you an error.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python Selenium .click() Loads Error - Works Manually.- Events not Triggered NSearch 24 1,064 Aug-14-2019, 02:23 PM
Last Post: NSearch
  Selenium click on popup button??? GuJu 7 974 Jul-20-2019, 09:21 AM
Last Post: Nizam
  Python Selenium getting table element trengan 2 1,393 Dec-31-2018, 03:02 PM
Last Post: trengan
  Selenium stale element reference test 1 540 Sep-19-2018, 10:19 PM
Last Post: test
  Selenium xpath finding gif to click fyec 1 910 Jul-27-2018, 05:20 PM
Last Post: snippsat
  Simple Element Check Code in Selenium Not Working digitalmatic7 1 781 Feb-18-2018, 06:53 AM
Last Post: metulburr
  Selenium chromedriver and click action Gilles95 4 6,499 Feb-07-2018, 07:28 PM
Last Post: Gilles95
  Selenium - Googlemaps element not visible Barnettch3 3 1,865 Jan-15-2018, 08:07 PM
Last Post: Barnettch3
  locating element with selenium after login sumandas89 1 1,198 Jan-15-2018, 02:40 PM
Last Post: metulburr
  Click on button with python mechanize torlkius 3 7,112 Jan-03-2018, 02:29 PM
Last Post: metulburr

Forum Jump:

Users browsing this thread: 1 Guest(s)