Python Forum
How do I iterate over an array and perform actions using selenium chrome webdriver?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I iterate over an array and perform actions using selenium chrome webdriver?
#1
I want to do a search for every element in an array

My code works and searches for the first element in the array only

Any ideas why it does not work for further elements?


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
import time

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://www.bing.com/search?q=test&form=QBLH&sp=-1&pq=test&sc=8-4&qs=n&sk=&cvid=E4AB1C52851A40EDB1B619B0CC4374A2")

time.sleep(5)

el = driver.find_element_by_xpath("//*[@id=\"sb_form_q\"]")
time.sleep(10)

codes = ['alpha', 'beta', 'gamma']
  
for code in codes:
  try:
    el.clear()
    el.send_keys(code)
    el.send_keys(Keys.RETURN)
    time.sleep(10)
  except:
    print('error')
    pass
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium- Can't access "Chrome is being controlled by automated test software" Lahva 0 1,152 Sep-19-2024, 11:37 AM
Last Post: Lahva
  Need help for script access via webdriver to an open web page in Firefox Clixmaster 1 2,384 Apr-20-2023, 05:27 PM
Last Post: farshid
  Problem with Selenium webdriver Fred 1 2,861 Jan-10-2022, 05:45 PM
Last Post: Larz60+
  Which webdriver is required for selenium in Pydroid App Rahatt 1 8,064 Jul-31-2020, 01:39 AM
Last Post: Larz60+
  Log In Button Won't Click - Python Selenium Webdriver samlee916 2 4,986 Jun-07-2020, 04:42 PM
Last Post: samlee916
  Hyperlink Click is not working in Selenium webdriver rajeev1729 0 2,513 May-02-2020, 11:21 AM
Last Post: rajeev1729
  How to perform a successful login(signin) through Requests in Python Kalet 1 3,044 Apr-24-2020, 01:44 AM
Last Post: Larz60+
  Extracting Text in a canvas using chain actions law 3 3,212 Apr-22-2020, 11:45 AM
Last Post: Larz60+
  Selenium/chrome console WiPi 4 7,385 Apr-12-2020, 11:45 AM
Last Post: WiPi
  Selenium webdriver error WiPi 4 15,469 Feb-09-2020, 11:38 AM
Last Post: WiPi

Forum Jump:

User Panel Messages

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