Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying with the try except way, I want the pass to pass when there is no item, but instead of passing the pass gives an error

Python
try:
                scamframe = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//iframe[@id='scmframe']")))
                driver.switch_to.frame(scamframe)
                contentfra = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "content")))
                driver.switch_to.frame(contentfra)
                commentframe = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "search-editor")))
                driver.switch_to.frame(commentframe)

                wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/c-wiz/div/div/c-wiz/div/div/div[2]/div[2]/div[1]/div[2]/textarea'))).send_keys("New Search")
                element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "/html[1]/body[1]/div[1]/c-wiz[1]/div[1]/div[1]/c-wiz[1]/div[1]/div[1]/div[2]/div[3]/div[1]/div[1]/span[1]/span[1]")))
                driver.execute_script("arguments[0].innerText = 'kSalih001'", element)
                WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//span[contains(text(),"kSalih001")]'))).click()
            except NoSuchElementException:
                try:
                    link = WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH,"//a[@id='search-editor-src']")))
                    print(link.get_attribute('href'))
                    driver.get(link.get_attribute('href'))
                except NoSuchElementException:
                    pass
                    print('Element Not Found!')
                    driver.quit()
                    os._exit(0)


What I have tried:

Python
try:
print("item found")
except NoSuchElementException:
print("item not found")
pass
Posted
Comments
Richard MacCutchan 15-Nov-22 3:56am    
"but instead of passing the pass gives an error"
What error?
kSalih54 15-Nov-22 4:50am    
commentframe = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "search-editor")))

this element not found error

It gives an error before reaching the transition part and the process ends
Richard MacCutchan 15-Nov-22 4:52am    
I say again, what error? If you do not tell us what the actual error is, then how do you expect us to help you?
kSalih54 15-Nov-22 4:59am    
Traceback (most recent call last):
File "c:\Users\kSalih\Desktop\ADV Blog\CookieYok.py", line 255, in <module>
cookie_yok(desktop + '\StepBlog//Config//allproxy.txt', firstLineprox)
File "c:\Users\kSalih\Desktop\ADV Blog\CookieYok.py", line 242, in cookie_yok
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//span[contains(text(),"kSalih001")]'))).click()
File "C:\Users\kSalih\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 88, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\kSalih\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute
return self._parent.execute(command, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Richard MacCutchan 15-Nov-22 5:01am    
:sigh: ??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900