Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Push Button on website
#1
Hello, I trying to do a script that open and push on a button automatically when run. As exemple I tried to open google.com and push on "google search automatically) but it doesnt work. Below is my code

import time
import webbrowser
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

 
driver = webdriver.Chrome()
url = "https://www.google.com/"
driver.get(url)

button = driver.find_element_by_xpath(//*[@id="L2AGLb"]/div)
clicking on the button
button.click()
buran write Feb-05-2024, 04:58 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Most first push accept all button.
Then input some text and search.
Code is old,have to setup chrome driver(in a OS path) first in code.
Old way find_element_by_xpath new find_element(By.XPATH, 'tag').
Here a working test.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

# Setup
#https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/121.0.6154.0/win64/chromedriver-win64.zip"
options = Options()
#options.add_argument("--headless=new")
ser = Service(r"C:\cmder\bin\chromedriver.exe")
browser = webdriver.Chrome(service=ser, options=options)
# Parse or automation
url = "https://www.google.com/"
browser.get(url)
time.sleep(3)
accept_bt = browser.find_element(By.CSS_SELECTOR, '#L2AGLb')
accept_bt.click()
input_field = browser.find_element(By.CSS_SELECTOR, '#APjFqb')
input_field.send_keys('car')
time.sleep(3)
search_bt = browser.find_element(By.XPATH, 'input.gNO89b')
search_bt.click()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Login and download an exported csv file within a ribbon/button in a website Alekhya 0 2,700 Feb-26-2021, 04:15 PM
Last Post: Alekhya
  Automated Git add/commit/push rxndy 0 2,066 May-13-2019, 11:51 AM
Last Post: rxndy
  data push from logger to server asdfasdf 2 3,723 May-02-2017, 11:32 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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