I wrote a program which is working and downloading the exact Excel files which I need . Unfortunately after two or 3 pages retrival, It starts to give the error. Here I can put some of the error which I receive them.
Error:
Exception has occurred: ElementClickInterceptedException
Message: Element <button id="d1yPj3" type="button"> is not clickable at point (57,945) because another element <div id="d1yP_k-mask" > obscures it
Stacktrace:
WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:188:5
ElementClickInterceptedError@chrome://remote/content/shared/webdriver/Errors.jsm:287:5
webdriverClickElement@chrome://remote/content/marionette/interaction.js:166:11
interaction.clickElement@chrome://remote/content/marionette/interaction.js:125:11
clickElement@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:205:29
receiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:93:31
File "C:\Users\SaeidVaygani\OneDrive - ISTA Mielke GmbH\Desktop\Saeid File\Web_Project\Programs\Tur_Details\Turk Test\Turkey_with_Clear_Button.py", line 118, in <module>
MenuPage_Button.click() # Menu Page Button
Or this Error:
Exception has occurred: ElementClickInterceptedException
Message: Element <button id="fAAAj3" type="button"> is not clickable at point (57,945) because another element <div id="fAAA_k-mask" > obscures it
Stacktrace:
WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:188:5
ElementClickInterceptedError@chrome://remote/content/shared/webdriver/Errors.jsm:287:5
webdriverClickElement@chrome://remote/content/marionette/interaction.js:166:11
interaction.clickElement@chrome://remote/content/marionette/interaction.js:125:11
clickElement@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:205:29
receiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.jsm:93:31
File "C:\Users\SaeidVaygani\OneDrive - ISTA Mielke GmbH\Desktop\Saeid File\Web_Project\Programs\Tur_Details\Turk Test\Turkey_with_Clear_Button.py", line 121, in <module>
MenuPage_Button.click() # Menu Page Button
Code trials:
from turtle import clear
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
my_Turkey_list = [
"02071110","02071130","02071190","02071210","02071290","02071310","02071320","02071330","02071340","02071350","02071360","02071370","02071391",
"02071399","02071410","02071420","02071430","02071440","02071450","02071460","02071470","02071491","02071499","02072490","02072590"],["02072630",
"02072670","02072699","02072710","02072720","02072730","02072740","02072750","02072760","02072780","02072791","02072799","02074230","02074280",
"02074561","02074593","02075551","02076005","02076051","02076099","04021011","04021019","04021091","04021099","04051010"],["04051011","04051019",
"04051030","04051050","04051090","04052010","04052030","04052090","04059010","04059090","07141000","07141010","07141091","07141098","07141099",
"11043090","12021090","12022000","12023000","12024100","12024200","12030000","12040010","12040090","12051010"],["12051090","12059000","12060010",
"12060090","12060091","12060099","12071000","12071010","12071090","12073000","12073010","12073090","12074010","12074090","12075010","12075090",
"12076000","12076090","12077000","12079110","12079190","12079210","12079290","12079910","12079915"],["12079920","12079991","12079996","12079997",
"12079998","12081000","12089000","15010011","15010019","15010090","15011010","15011090","15012010","15012090","15019000","15020010","15020090",
"15021010","15021090","15029010","15029090","15030011","15030019","15030030","15030090"],["15041010","15041090","15041091","15041099","15042010",
"15042090","15043010","15043011","15043019","15043090","15050010","15050090","15060000","15071010","15071090","15079010","15079090","15081010",
"15081090","15089010","15089090","15091010","15091020","15091080","15091090"],["15099000","15100010","15100090","15111010","15111090","15119011",
"15119019","15119091","15119099","15121110","15121191","15121199","15121910","15121990","15121991","15121999","15122110","15122190","15122910",
"15122990","15131110","15131191","15131199","15131911","15131919"],["15131930","15131991","15131999","15132110","15132111","15132119","15132130",
"15132190","15132911","15132919","15132930","15132950","15132990","15132991","15132999","15141110","15141190","15141910","15141990","15149110",
"15149190","15149910","15149990","15151100","15151910"],["15151990","15152110","15152190","15152910","15152990","15153010","15153090","15154000",
"15155011","15155019","15155091","15155099","15156000","15159010","15159011","15159015","15159021","15159029","15159031","15159039","15159040",
"15159051","15159059","15159060","15159091"],["15159099","15161010","15161090","15162010","15162091","15162095","15162096","15162098","15162099",
"15171010","15171090","20081110","20081191","20081192","20081194","20081196","20081198","20081199","23012000","23031011","23031019","23031090",
"23040000","23050000","23061000"],["23062000","23063000","23064100","23064900","23065000","23066000","23067000","23069005","23069011","23069019",
"23069090","23069093","23099010","38260010","38260090","12010010","12010090","12011000","12019000","12021010","12072010","12072090","12072100",
"12072900","23033000"]
print("-------------------------------------")
Tur_Im_Start_Year = input(" Year like '20XX':")
print()
print("<< All months >>, January , February , March , April , May , June ")
print("July , August , September , October , November , December")
print()
Tur_Im_Start_Month = input(" Month Exactly Like above:")
print("-------------------------------------")
# driver = webdriver.Chrome('C:\Webdriver\chromedriver.exe')
driver = webdriver.Firefox(executable_path=r'C:\Webdrivers\geckodriver.exe')
driver.get('https://biruni.tuik.gov.tr/disticaretapp/menu_ing.zul')
time.sleep(2)
for i in range (len(my_Turkey_list)):
driver.maximize_window()
element = driver.find_element(by=By.XPATH,value='//*[contains(text(), "Product/Product Groups-Partner Country")]')
element.click()
time.sleep(2)
radio_element_ppc = driver.find_element(by=By.XPATH,value='//*[contains(text(), "Product/Partner Country")]')
radio_element_ppc.click()
time.sleep(2)
radio_element_HarSys=driver.find_element(By.XPATH,'/html/body/div/div/div/table/tbody/tr/td/table/tbody/tr[3]/td/'\
'div/div/table/tbody[1]/tr[14]/td/div/table/tbody/tr/td/table/tbody/tr[3]/td/span/span[1]/input')
radio_element_HarSys.click()
time.sleep(1)
radio_element_HS8=driver.find_element(By.XPATH,'/html/body/div/div/div/table/tbody/tr/td/table/tbody/tr[3]/td/div/'\
'div/table/tbody[1]/tr[15]/td/div/span/span[4]/input')
radio_element_HS8.click()
time.sleep(1)
Next_btn=driver.find_element(By.XPATH,'/html/body/div/div/div/table/tbody/tr/td/table/tbody/tr[3]/td/div/div/table/'\
'tbody[1]/tr[17]/td/div/table/tbody/tr/td/table/tbody/tr/td[1]/button')
Next_btn.click()
time.sleep(4)
# page 2
Year_Radio=driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[5]/'\
'td/div/div/table/tbody[1]/tr/td/div/table/tbody/tr/td/table/tbody/tr/td[1]/table/tbody/tr/td/table/tbody/tr/td/span/span[1]/label')
Year_Radio.click()
time.sleep(2)
ListBox_Year_Select = driver.find_element(by=By.XPATH,value="//*[contains(text(),'{}')]".format(str(Tur_Im_Start_Year)))
ListBox_Year_Select.click()
time.sleep(2)
Month_Radio=driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[5]/td/'\
'div/div/table/tbody[1]/tr/td/div/table/tbody/tr/td/table/tbody/tr/td[1]/table/tbody/tr/td/table/tbody/tr/td/span/span[2]/input')
Month_Radio.click()
time.sleep(2)
ListBox_Month_Select = driver.find_element(by=By.XPATH,value="//*[contains(text(),'{}')]".format(Tur_Im_Start_Month))
ListBox_Month_Select.click()
time.sleep(2)
I_know_HS8_code_Radio=driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[7]/'\
'td/div/div/table/tbody[1]/tr[2]/td/div/table/tbody/tr/td/table/tbody/tr[11]/td/span/span[2]/label')
I_know_HS8_code_Radio.click()
time.sleep(2)
for j in range (25):
driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[7]/td/'\
'div/div/table/tbody[1]/tr[3]/td/div/input').send_keys(my_Turkey_list[i][j])
if(j==24):
break
else:
driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[7]/td/'\
'div/div/table/tbody[1]/tr[3]/td/div/input').send_keys(",")
time.sleep(2)
Country_information_Radio=driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/'\
'tbody/tr[9]/td/div/div/table/tbody[1]/tr[2]/td/div/table/tbody/tr/td/table/tbody/tr[11]/td/span/span[1]/label')
Country_information_Radio.click()
time.sleep(2)
Country_All_Select = driver.find_element(by=By.XPATH,value='//*[contains(text(), "<< All >>")]')
Country_All_Select.click()
time.sleep(2)
#--------------------------------------------
Import_ChkBox=driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[11]/td/div/div/table/tbody[1]/tr[1]/td/div/table/tbody/tr/td/table/tbody/tr/td[5]/span/label')
Import_ChkBox.click()
time.sleep(2)
Value_Euro_ChkBox=driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[11]/td/div/div/table/tbody[1]/tr[2]/td/div/table/tbody/tr/td/table/tbody/tr/td[5]/span/label')
Value_Euro_ChkBox.click()
time.sleep(2)
Excel_Type_Radio=driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[13]/'\
'td/div/div/table/tbody[1]/tr/td[1]/div/table/tbody/tr/td/table/tbody/tr/td[3]/span/span[2]/input')
Excel_Type_Radio.click()
time.sleep(2)
driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[17]/td/div/div[3]/table/'\
'tbody[2]/tr/td[2]/div/button').click() # to download
time.sleep(10)
MenuPage_Button=driver.find_element(By.XPATH,'/html/body/div/div/div[2]/div/div/div/table/tbody/tr/td/table/tbody/tr[17]/td/div/'\
'div[3]/table/tbody[2]/tr/td[1]/div/table/tbody/tr/td/table/tbody/tr/td[1]/button')
MenuPage_Button.click() # Menu Page Button
time.sleep(3)
CodePudding user response:
Try clicking on the child of the element:
child = clicked_element.find_elements_by_css_selector("*")
Or, just try clicking on the parent of the element you are clicking:
parent = clicked_elemnet.find_element_by_xpath('..')
Clicking on the child or the parent should resolve your issue.
CodePudding user response:
Presumably you are invoking the click too early even before the desired element reaching the interactable state.
Solution
Ideally, to click on the clickable element would be to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.z-button-os"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='z-button-os']"))).click()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
A canonical approach would be to induce WebDriverWait for the invisibility_of_element() for the obscuring element as follows:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.CSS_SELECTOR, "div.z-modal-mask"))) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.z-button-os"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='z-modal-mask']"))) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='z-button-os']"))).click()