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
  Need help for script access via webdriver to an open web page in Firefox Clixmaster 1 1,247 Apr-20-2023, 05:27 PM
Last Post: farshid
  How do I get rid of "Chrome is being controlled by automated test software"? jetBlack 2 12,762 Jul-21-2022, 08:31 AM
Last Post: Benjamin112
  Problem with Selenium webdriver Fred 1 2,030 Jan-10-2022, 05:45 PM
Last Post: Larz60+
  Which webdriver is required for selenium in Pydroid App Rahatt 1 6,299 Jul-31-2020, 01:39 AM
Last Post: Larz60+
  Log In Button Won't Click - Python Selenium Webdriver samlee916 2 3,811 Jun-07-2020, 04:42 PM
Last Post: samlee916
  Expose chrome extension buttons to Python robertjaxe 2 2,341 May-12-2020, 07:52 PM
Last Post: robertjaxe
  Hyperlink Click is not working in Selenium webdriver rajeev1729 0 2,013 May-02-2020, 11:21 AM
Last Post: rajeev1729
  How to perform a successful login(signin) through Requests in Python Kalet 1 2,329 Apr-24-2020, 01:44 AM
Last Post: Larz60+
  Extracting Text in a canvas using chain actions law 3 2,292 Apr-22-2020, 11:45 AM
Last Post: Larz60+
  Selenium/chrome console WiPi 4 5,870 Apr-12-2020, 11:45 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