Click button with selenium and python

2024/11/14 11:42:37

I'm trying to do web scraping with python on and I'm having trouble clicking buttons. I've tried 3 different youtube videos using Xpath, driver.find_element_by_link_text, and driver.find_element.

What am I missing?

https://i.sstatic.net/GnzMU.png https://i.sstatic.net/NfLfX.png https://i.sstatic.net/SkUPL.png

I've tried 3 different youtube videos using Xpath, driver.find_element_by_link_text, and driver.find_element.

https://youtu.be/USrjHgO9Niw https://youtu.be/TvkRseysDr0 https://youtu.be/U6gbGk5WPws

Answer

The javascript for the start button is taking a tiny bit longer to load in, than when selenium thinks the page is finished loading..so it ends up searching for the element and it's not there yet.

All your code needs is a wait for the element to be present on the page.

I also changed the search for the start button, since I was finding multiple elements

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 ECdef initialize_browser():driver=webdriver.Chrome()driver.get("https://virtualracingschool.appspot.com")wait = WebDriverWait(driver, 30)startRacingXpath = '//*[contains(text(), "Join any iRacing session")]/following-sibling::*'click_button = wait.until(EC.presence_of_element_located((By.XPATH, startRacingXpath)))click_button.click()initialize_browser()
https://en.xdnf.cn/q/120496.html

Related Q&A

Combinations of DataFrames from list

I have this:dfs_in_list = [df1, df2, df3, df4, df5]I want to concatenate all combinations of them one after the other (in a loop), like:pd.concat([df1, df2], axis=1) pd.concat([df1, df3], axis=1) p…

Python: iterate through dictionary and create list with results

I would like to iterate through a dictionary in Python in the form of:dictionary = {company: {0: apple,1: berry,2: pear},country: {0:GB,1:US,2:US} }To grab for example: every [company, country] if coun…

Jira Python: Syntax error appears when trying to print

from jira.client import jiraoptions = {server: https://URL.com} jira = JIRA(options, basic_auth=(username, password))issues = jira.search_issues(jqlquery) for issue in issues:print issueI want to print…

Matplotlib plt.xlim([x_min,x_max]), list object not callable

I want to plot a scatterplot, but set the x-label limits.axScatter = plt.subplot(111) axScatter.scatter(x=mean_var_r["Variance"],y=mean_var_r["Mean"]) xlim = [-0.003, 0.003] plt.xli…

Map column birthdates in python pandas df to astrology signs

I have a dataframe with a column that includes individuals birthdays. I would like to map that column to the individuals astrology sign using code I found (below). I am having trouble writing the code …

How to use python pandas to find a specific string in various rows

I am trying to do my taxes. I have over 2,000 rows of data in a CSV of orders. I am trying to just count and print the rows that contain "CA" so I know the ones I need to pay sales tax on. I …

How to cast a list to a dictionary

I have a list as a input made from tuples where the origin is the 1st object and the neighbour is the 2nd object of the tuple. for example :inp : lst = [(a,b),(b,a),(c,),(a,c)] out : {a: (a, [b, c]), …

Couldnt get rid of (_tkinter.TclError: bad event type or keysym UP) problem

I am running a Linux mint for the first time . I tried coding a python problem but for two days I am continiously facing problems due to Linux interface please This is my code:-import turtleimport time…

WMI lib to start windows service remotely

How do I start a service using the WMI library? The code below throws the exception: AttributeError: list object has no attribute StopServiceimport wmi c = wmi.WMI (servername,user=username,password=p…

TutorialsPoint - Flask – SQLAlchemy not working

I did all that was stated on tutorial point (just copied and pasted), but when I tried to add a student entry,i.e. ‘Add Student’ it givesBad Request The browser (or proxy) sent a request that this se…