My python selenium code is working fine. I am automating 3 web pages. In the second web page I have 5 radio buttons to click. My code works for 8-10 times but after that it gives me this error: selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (256, 10). Other element would receive the click Its bit strange because it works for some time like 5-8 times but after that it just stops working and gives me this error. How to fix this. I have tried the execute_script() method but still its not working.
The part which is giving me the error
radio_1 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[1]/div[2]/div[1]/label[1]/input')
driver.execute_script("arguments[0].click();", radio_1)
radio_1.click()
Here is the full code
from sre_parse import State
from tkinter.tix import Select
from unicodedata import name
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.alert import Alert
import pandas as pd
import xlrd
import time
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
# readign the excel file
df = pd.read_excel('New1Rajnandgaon_List.xlsx')
# looping through all the data
for i in df.index:
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), chrome_options=chrome_options)
alert = Alert(driver)
time.sleep(3)
driver.get("https://ssg2021.in/citizenfeedback")
time.sleep(3)
# selcting states
state_select = driver.find_element(By.XPATH,'//*[#id="State"]')
drp1 = Select(state_select)
drp1.select_by_visible_text('Chhattisgarh')
time.sleep(2)
# selecting district
district_select = driver.find_element(By.XPATH,'//*[#id="District"]')
drp2 = Select(district_select)
drp2.select_by_visible_text('RAJNANDGAON')
entry = df.loc[i]
# entering the age
age = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[1]/div/div/input')
age.send_keys(str(entry['age']))
# respondant name
rs_name = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[1]/div/input')
rs_name.send_keys(entry['name'])
# rs mobile number
rs_number = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[2]/div/input')
rs_number.send_keys(str(entry['mobile number']))
# rs gender
gender = driver.find_element(By.XPATH,'//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[3]/div/select')
rs_gender = Select(gender)
rs_gender.select_by_visible_text('Male')
# submitting the form
submit = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[5]/input')
submit.click()
time.sleep(2)
# second page
# radio button 1
radio_1 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[1]/div[2]/div[1]/label[1]/input')
driver.execute_script("arguments[0].click();", radio_1)
radio_1.click()
# radio button 2
radio_2 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[2]/div[2]/div[1]/label[1]')
radio_2.click()
# radio button 3
radio_3 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[3]/div[2]/div[1]/label[1]')
radio_3.click()
# radio button 4
radio_4 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[4]/div[2]/div[1]/label[1]')
radio_4.click()
# radio button 5
radio_5 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[5]/div[2]/div[1]/label[1]')
radio_5.click()
submit2 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[2]/input')
submit2.click()
# alert
WebDriverWait(driver, 10).until(EC.alert_is_present())
alert = driver.switch_to.alert
alert.accept()
driver.close()
Related
I would like to download .csv reports for all states and all compliance periods from this web page.
In other words, the selenium script would select a state (for example, "DC") a reporting period (for example, "Jan 2021 - Dec 2021"), and then click "submit." THEN the script would export the results to a spreadsheet by clicking the image that says "CSV".
Ideally, the spreadsheet would do this for all states and all reporting periods. So at the end, my downloads folder would be full of spreadsheets.
I cannot, for the life of me, figure out how to get this to work!
This is what I have so far. There are no loops like I think there should be.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import chromedriver_autoinstaller
import time
import glob
import os
chromedriver_autoinstaller.install()
chromeOptions = webdriver.ChromeOptions()
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
url = "https://gats.pjm-eis.com/GATS2/PublicReports/RPSRetiredCertificatesReportingYear"
driver.get(url)
driver.find_element(By.CSS_SELECTOR, "table:nth-child(4)").click()
driver.find_element(By.ID, "SelectedState0_B-1").click()
driver.find_element(By.ID, "SelectedState0_DDD_L_LBI5T0").click()
driver.find_element(By.ID, "ReportingYear0_B-1").click()
driver.find_element(By.ID, "ReportingYear0_DDD_L_LBI0T0").click()
driver.find_element(By.CSS_SELECTOR, ".dx-vam:nth-child(2)").click()
driver.find_element(By.ID, "CSV0Img").click()
Thank you very much for your help! I truly appreciate it.
Here is the Solution!
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
import glob
import os
chromeOptions = webdriver.ChromeOptions()
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
url = "https://gats.pjm-eis.com/GATS2/PublicReports/RPSRetiredCertificatesReportingYear"
state = 'DC' # Enter State Name Here
compliance_period = 'Jan 2020 - Dec 2020' # Enter Compliance Period Here
driver.get(url)
wait.until(EC.element_to_be_clickable((By.XPATH, '(//*[#class="dxEditors_edtDropDown_GATS2"])[1]'))).click() # Clicking on Dropdown Arrow Down Icon
wait.until(EC.element_to_be_clickable((By.XPATH, '//tr[#class="dxeListBoxItemRow_GATS2"]//td[text()="' + state + '"]'))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, '(//*[#class="dxEditors_edtDropDown_GATS2"])[2]'))).click() # Clicking on Dropdown Arrow Down Icon
wait.until(EC.element_to_be_clickable((By.XPATH, '//tr[#class="dxeListBoxItemRow_GATS2"]//td[text()="' + compliance_period + '"]'))).click()
driver.find_element(By.XPATH, '//*[text()="Submit"]').click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[#id="CSV0Img"]'))).click()
print("Successfully Downloaded!")
time.sleep(10)
driver.quit()
* Updated another Solution below as per the case mentioned in the comments where we've to make it loop through all the states and through all the compliance periods.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
chromeOptions = webdriver.ChromeOptions()
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
url = "https://gats.pjm-eis.com/GATS2/PublicReports/RPSRetiredCertificatesReportingYear"
driver.get(url)
count_state = len(driver.find_elements(By.XPATH, '//table[#id="SelectedState0_DDD_L_LBT"]//tr'))
for i in range(1, count_state + 1):
wait.until(EC.element_to_be_clickable((By.XPATH, '(//*[#class="dxEditors_edtDropDown_GATS2"])[1]'))).click() # Clicking on Dropdown Arrow Down Icon
wait.until(EC.element_to_be_clickable((By.XPATH, '(//table[#id="SelectedState0_DDD_L_LBT"]//tr)[' + str(i) + ']'))).click()
state_name = driver.find_element(By.XPATH, '(//table[#id="SelectedState0_DDD_L_LBT"]//tr/td)[' + str(i) + ']').get_attribute("textContent")
count_period = len(driver.find_elements(By.XPATH, '//table[#id="ReportingYear0_DDD_L_LBT"]//tr'))
for j in range(1, count_period + 1):
wait.until(EC.element_to_be_clickable((By.XPATH, '(//*[#class="dxEditors_edtDropDown_GATS2"])[2]'))).click() # Clicking on Dropdown Arrow Down Icon
wait.until(EC.element_to_be_clickable((By.XPATH, '(//table[#id="ReportingYear0_DDD_L_LBT"]//tr)[' + str(j) + ']'))).click()
driver.find_element(By.XPATH, '//*[text()="Submit"]').click()
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[#id="CSV0Img"]'))).click()
compliance_period_name = driver.find_element(By.XPATH, '(//table[#id="ReportingYear0_DDD_L_LBT"]//tr/td)[' + str(j) + ']').get_attribute("textContent")
print("Successfully Downloaded for State:", state_name, " and Compliance Period: ", str(compliance_period_name))
print("\n")
time.sleep(10)
driver.quit()
I am trying to scrape this website: https://www.longos.com/flyers.
I've been able to enter the postal code (ex.M5B 0B7 for people who may not be familiar with postal codes in this area) , click on the closest store and have the flyer pop up.
However, I am having troubles clicking into the specific flyer page, get the particular product and get the text information. The code below is my attempt.
i = 1
while True:
flyer_link = "/html/body/flipp-router/flipp-publication-page/div/flipp-sfml-component/sfml-storefront/div/sfml-linear-layout/sfml-flyer-image[{}]".format(i)
print(flyer_link)
flyer = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, flyer_link)))
print(flyer)
i+=1
It doesn't seem to be abble to recognize the XPATH
Here is a snapshot of the html code for reference:
j = 1
for i in prdcts:
driver.execute_script("arguments[0].scrollIntoView();", i)
i.click()
time.sleep(3)
print(i)
# print(driver.page_source)
i = 1
while True:
try:
button_link_to_text = '/html/body/flipp-router/flipp-publication-page/div/flipp-sfml-component/sfml-storefront/div/sfml-linear-layout/sfml-flyer-image[{}]/div/button[{}]'.format(j,i)
button = driver.find_element_by_xpath(button_link_to_text)
print(button.get_attribute("aria-label"))
i+=1
except:
break
j+=1
Try this
from selenium.webdriver.common.action_chains import ActionChains
import time
from webdriver_manager.chrome import ChromeDriverManager
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 EC
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get('https://www.longos.com/flyers')
time.sleep(5)
iframe = driver.find_element_by_xpath('//iframe[#class="flippiframe productframe"]')
driver.switch_to.frame(iframe)
eleme = driver.find_element_by_xpath('//input[#id="postal-input"]')
eleme.send_keys("M5B0B7")
eleme = driver.find_element_by_xpath('//button[#id="submit-postal-code"]').click()
time.sleep(2)
eleme = driver.find_element_by_xpath('//button [#aria-label="Select Elizabeth 111 Elizabeth Street Toronto ON, distance from store is <1 km"]').click()
driver.switch_to.default_content()
time.sleep(5)
iframe = driver.find_element_by_xpath('//iframe[#class="flippiframe mainframe"]')
driver.switch_to.frame(iframe)
prdcts = driver.find_elements_by_xpath('//sfml-flyer-image//button')
print (prdcts)
for i in prdcts:
driver.execute_script("arguments[0].scrollIntoView();", i)
print(i.get_attribute("aria-label"))
time.sleep(3)
print(I)
and don't forget to switch back to class="flippiframe productframe"] this frame to get the product details.
the main thing is you need to switch the iframes and get into view to interact with that element
So I am working with selenium in python. I am automating 3 web pages. In my first page if a mobile number is already filled, my second page gives me this error with a modal : This Mobile No is already attached to a submitted feedback. Now because of this my selenium program just stops. I want to click Ok in the modal and accept it and just close the browser window and then restart my program. How do I do that ?
Error window
My code
from sre_parse import State
from tkinter.tix import Select
from unicodedata import name
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.alert import Alert
import pandas as pd
import xlrd
import time
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
# readign the excel file
df = pd.read_excel('New1Rajnandgaon_List.xlsx')
# looping through all the data
for i in df.index:
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), chrome_options=chrome_options)
alert = Alert(driver)
time.sleep(3)
driver.get("https://ssg2021.in/citizenfeedback")
time.sleep(3)
# selcting states
state_select = driver.find_element(By.XPATH,'//*[#id="State"]')
drp1 = Select(state_select)
drp1.select_by_visible_text('Chhattisgarh')
time.sleep(2)
# selecting district
district_select = driver.find_element(By.XPATH,'//*[#id="District"]')
drp2 = Select(district_select)
drp2.select_by_visible_text('RAJNANDGAON')
entry = df.loc[i]
# entering the age
age = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[1]/div/div/input')
age.send_keys(str(entry['age']))
# respondant name
rs_name = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[1]/div/input')
rs_name.send_keys(entry['name'])
# rs mobile number
rs_number = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[2]/div/input')
rs_number.send_keys(str(entry['mobile number']))
# rs gender
gender = driver.find_element(By.XPATH,'//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[3]/div/select')
rs_gender = Select(gender)
rs_gender.select_by_visible_text('Male')
# submitting the form
submit = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[5]/input')
submit.click()
time.sleep(2)
# second page
# radio button 1
radio_1 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[1]/div[2]/div[1]/label[1]/input')
driver.execute_script("arguments[0].click();", radio_1)
radio_1.click()
# radio button 2
radio_2 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[2]/div[2]/div[1]/label[1]')
radio_2.click()
# radio button 3
radio_3 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[3]/div[2]/div[1]/label[1]')
radio_3.click()
# radio button 4
radio_4 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[4]/div[2]/div[1]/label[1]')
radio_4.click()
# radio button 5
radio_5 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[5]/div[2]/div[1]/label[1]')
radio_5.click()
submit2 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[2]/input')
submit2.click()
# alert
time.sleep(1)
driver.close()
You need to switch to this alert and accept it as following:
WebDriverWait(driver, 20).until(EC.alert_is_present())
alert = driver.switch_to.alert
alert.accept()
So I am using selenium for my web automation. I have a excel sheet with my data entries. Right now I am able to fill my excel entries but its filling only first entry after that my program just stops. I have more than 1,50,000 entries. I want my program to keep running until it fills all the entries in my form. How do I do that. Please help me !
My Entries in excel
My code
from sre_parse import State
from tkinter.tix import Select
from unicodedata import name
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import pandas as pd
import xlrd
import time
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), chrome_options=chrome_options)
driver.get("https://ssg2021.in/citizenfeedback")
# readign the excel file
df = pd.read_excel('Rajnandgaon_List2.xlsx')
# looping through all the data
for i in df.index:
time.sleep(3)
# selcting states
state_select = driver.find_element(By.XPATH,'//*[#id="State"]')
drp1 = Select(state_select)
drp1.select_by_visible_text('Chhattisgarh')
time.sleep(2)
# selecting district
district_select = driver.find_element(By.XPATH,'//*[#id="District"]')
drp2 = Select(district_select)
drp2.select_by_visible_text('RAJNANDGAON')
entry = df.loc[i]
# entering the age
age = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[1]/div/div/input')
age.send_keys(str(entry['age']))
# respondant name
rs_name = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[1]/div/input')
rs_name.send_keys(entry['name'])
# rs mobile number
rs_number = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[2]/div/input')
rs_number.send_keys(str(entry['mobile number']))
# rs gender
gender = driver.find_element(By.XPATH,'//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[3]/div/select')
rs_gender = Select(gender)
rs_gender.select_by_visible_text('Male')
# submitting the form
submit = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[5]/input')
submit.click()
# second page
# radio button 1
radio_1 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[1]/div[2]/div[1]/label[1]/input')
radio_1.click()
# radio button 2
radio_1 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[2]/div[2]/div[1]/label[1]')
radio_1.click()
# radio button 3
radio_1 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[3]/div[2]/div[1]/label[1]')
radio_1.click()
# radio button 4
radio_1 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[4]/div[2]/div[1]/label[1]')
radio_1.click()
# radio button 5
radio_1 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[5]/div[2]/div[1]/label[1]')
radio_1.click()
submit2 = driver.find_element(By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[2]/input')
submit2.click()
Your problem can be solve using below code:
from sre_parse import State
from tkinter.tix import Select
from unicodedata import name
from selenium import webdriver
from selenium.webdriver.support.select import Select
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import pandas as pd
import xlrd
import time
import openpyxl
# readign the excel file
ExcelPath = 'Excel_Path'
df = pd.read_excel(ExcelPath)
wb = openpyxl.load_workbook(ExcelPath)
ws = wb.worksheets[0]
maxrow = ws.max_row
# looping through all the data
for i in range(2, maxrow + 1):
# Every Time Browser will open
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome()
driver.get("https://ssg2021.in/citizenfeedback")
time.sleep(3)
# selcting states
state_select = driver.find_element(By.XPATH, '//*[#id="State"]')
drp1 = Select(state_select)
drp1.select_by_visible_text('Chhattisgarh')
time.sleep(2)
# selecting district
district_select = driver.find_element(By.XPATH, '//*[#id="District"]')
drp2 = Select(district_select)
drp2.select_by_visible_text('RAJNANDGAON')
entry = df.loc[i]
# entering the age
age = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[1]/div/div/input')
age.send_keys(str(entry['age']))
# respondant name
rs_name = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[1]/div/input')
rs_name.send_keys(entry['name'])
# rs mobile number
rs_number = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[2]/div/input')
rs_number.send_keys(str(entry['mobile number']))
# rs gender
gender = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[4]/div[2]/div/div[3]/div/select')
rs_gender = Select(gender)
rs_gender.select_by_visible_text('Male')
# submitting the form
submit = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[1]/form/div[5]/input')
submit.click()
# second page
# radio button 1
radio_1 = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[1]/div[2]/div[1]/label[1]/input')
radio_1.click()
# radio button 2
radio_1 = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[2]/div[2]/div[1]/label[1]')
radio_1.click()
# radio button 3
radio_1 = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[3]/div[2]/div[1]/label[1]')
radio_1.click()
# radio button 4
radio_1 = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[4]/div[2]/div[1]/label[1]')
radio_1.click()
# radio button 5
radio_1 = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[1]/div[5]/div[2]/div[1]/label[1]')
radio_1.click()
submit2 = driver.find_element(
By.XPATH, '//*[#id="zed_user_form"]/div/div[1]/div[2]/div/div/div[2]/form/div[2]/input')
submit2.click()
# After Clicking Submit Button Browser Will Quit
driver.quit()
I'm trying to automate a form assertion with a list of data, however I'm struggling on when and how to use "WebDriverWait" or driver implict wait. My list is 1000 strings. When I run a sample of a 100, less than 100 are captured correctly. The code below catches ElementNotSelectableException\StaleElementReferenceException but doesn't address them correctly.
import unittest
from selenium.common.exceptions import ElementNotVisibleException, ElementNotSelectableException, \
ElementNotInteractableException, StaleElementReferenceException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
oar_order_id = '#oar-order-id'
oar_zip_code = '#oar_zip'
#order confirmation list
order_id_list = ["WO-34284975","WO-50002804","WO-50004302","WO-34282964","WO-34214963"]
#zip code confirmation list
zip_code_list = ["23508","99338","62036","75074-7520","37763","98034","89406-4361"]
submit_button = 'body.sales-guest-form.page-layout-1column:nth-child(2) div.page-wrapper:nth-child(10) main.page-main:nth-child(4) div.columns:nth-child(4) div.column.main form.form.form-orders-search:nth-child(4) div.actions-toolbar div.primary > button.action.submit.primary'
# Enter orderid & Zip & click enter
found = []
notfound = []
length = len(order_id_list)
driver.implicitly_wait(10)
wait = WebDriverWait(driver, 15, poll_frequency=1,
ignored_exceptions=[ElementNotVisibleException ,ElementNotSelectableException])
driver.get('https:/www.ecklers.com/sales/orderlookup/index/')
# Sample of 10 from list
for i in range(10):
try:
wait
element1 = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, oar_order_id)))
element1.send_keys(order_id_list[i])
element2 = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, oar_zip_code)))
element2.send_keys(zip_code_list[i])
element3 = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, submit_button)))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, submit_button)))
element3.click()
wait
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"body.sales-guest-view.page-layout-1column:nth-child(2) div.page-wrapper:nth-child(10) main.page-main:nth-child(4) div.page-title-wrapper:nth-child(3) h1.page-title > span.base")))
title = driver.title
#driver.implicitly_wait(60)
except(StaleElementReferenceException):
print("StaleElementReferenceException")
except(ElementNotInteractableException):
print("ElementNotInteractableException")
try:
text = order_id_list[i]
assert(title.endswith(text[3:]))
found.append(text)
except(AssertionError):
notfound.append((order_id_list[i]))
driver.get('https:/www.ecklers.com/sales/orderlookup/index/')
wait
print(found,notfound)```
I found an answer that helped me. I used: time.sleep(.500) after driver.get('https:/www.ecklers.com/sales/orderlookup/index/'