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
  Problem with Selenium webdriver Fred 1 129 Jan-10-2022, 05:45 PM
Last Post: Larz60+
  Which webdriver is required for selenium in Pydroid App Rahatt 1 2,575 Jul-31-2020, 01:39 AM
Last Post: Larz60+
  Log In Button Won't Click - Python Selenium Webdriver samlee916 2 1,963 Jun-07-2020, 04:42 PM
Last Post: samlee916
  Hyperlink Click is not working in Selenium webdriver rajeev1729 0 962 May-02-2020, 11:21 AM
Last Post: rajeev1729
  How to perform a successful login(signin) through Requests in Python Kalet 1 1,370 Apr-24-2020, 01:44 AM
Last Post: Larz60+
  Extracting Text in a canvas using chain actions law 3 1,285 Apr-22-2020, 11:45 AM
Last Post: Larz60+
  Selenium/chrome console WiPi 4 3,422 Apr-12-2020, 11:45 AM
Last Post: WiPi
  Selenium webdriver error WiPi 4 6,744 Feb-09-2020, 11:38 AM
Last Post: WiPi
  Chrome instead of IE Friend 1 1,076 Feb-09-2020, 07:31 AM
Last Post: Larz60+
  Headless Chrome: How to login into a webpage? amandacstr 1 1,969 Feb-06-2020, 02:19 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

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