Bottom Page

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()
Larz60+ wrote Mar-21-2020, 05:43 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#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
Quote
#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)
Larz60+ wrote Mar-21-2020, 11:47 PM:
Please post all code, output and errors (in it's entirety) between their respective tags. Refer to BBCode help topic on how. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  bypassing find element click() windows11 1 67 Apr-02-2020, 11:55 AM
Last Post: Larz60+
  wait.until(EC.element_to_be_clickable) failed to click gahhon 4 1,447 Feb-23-2019, 04:58 AM
Last Post: gahhon
  Click Element if displayed using Selenium and Python giaco__mar 1 1,184 Dec-27-2018, 06:19 PM
Last Post: metulburr

Forum Jump:


Users browsing this thread: 1 Guest(s)