Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
wait for element and click
#1
Hello world, I need some help Pray . I´m try to search and did´t find the solution or it was to confuse. Huh

I'm trying to wait for the element to be visible in the website to open, right now I have a time, but some times the internet is slow and I can´t open. I would like to have something like "wait until the element appear and click()"

thank you Heart

this is my code:


from selenium import webdriver

browser=webdriver.Firefox(executable_path="C:\\Users\\Sabrina\\Desktop\\geckodriver-v0.26.0-win64\\geckodriver.exe")

browser.get("website link, for exemple www.youtube.com")

import time
time.sleep(8)

browser.find_element_by_xpath("/html/body/div[2]/main/div/div[2]/section[1]").click()

import time
time.sleep(8)

browser.find_element_by_xpath("/html/body/div[2]/main/div[2]/section[1]").click()
Reply
#2
1st only import packages once, usually at the start of the program
You need to learn more about scraping.
Please do the following tutorials:
web scraping part 1
web scraping part 2
Reply
#3
Found it how I do. If some one have the same question is here the solution

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


def init_driver():
driver=webdriver.Firefox(executable_path="C:\\Users\\SAbrina\\Desktop\\geckodriver-v0.26.0-win64\\geckodriver.exe")
driver.wait=WebDriverWait(driver, 5)
return driver



def get_data(driver):
driver.get("website link")
element=driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/main/div/div[2]/section[1]")))
driver.find_element_by_xpath("/html/body/div[2]/main/div/div[2]/section[1]").click()

driver=init_driver()
get_data(driver)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Help with Selenium Explicit Wait gw1500se 6 2,901 Nov-28-2021, 09:44 PM
Last Post: Larz60+
  selenium wait for text question Larz60+ 3 2,543 Oct-25-2021, 09:50 AM
Last Post: Larz60+
  Unable to click element in web page Kalpana 0 1,861 Jun-25-2020, 05:20 AM
Last Post: Kalpana
  find element...click() dont work windows11 6 3,136 Apr-23-2020, 11:13 PM
Last Post: law
  drive wait in try windows11 0 1,822 Apr-07-2020, 01:50 PM
Last Post: windows11
  bypassing find element click() windows11 1 1,881 Apr-02-2020, 11:55 AM
Last Post: Larz60+
  wait.until(EC.element_to_be_clickable) failed to click gahhon 4 7,987 Feb-23-2019, 04:58 AM
Last Post: gahhon
  Click Element if displayed using Selenium and Python giaco__mar 1 3,538 Dec-27-2018, 06:19 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020