elem1 = driver.find_elements(By.XPATH,"//select[@class='ageselect']") if len(elem1) == 0: print("Element is not in DOM") if len(elem1) > 0 and elem1[0].is_displayed()==False: print("Element is in DOM but not displayed") you can use this code. use elem1 to save all result of finding web element - If cannot find age element in DOM -> print message "Element is not in DOM" instead of error log - If can find age element in DOM but it is not displayed -> print message "Element is in DOM but not displayed"
If you time for a question, I would appreciate some guidance. I have been trying for days (not kidding) to locate the second Accordion Item in a Python-Dash dbc.Accordion. The html code also has a "flex" badge so I assume it uses flexbox as well. There just is not much documentation at all. I have tried every selector, every path and I can't make it happen. I am posting the code below just in case you can help. I get error messages mostly telling me it cant click at the given coordinates. I know this question is a shot in the dark. But I am at that point. Thank you in advance for any feedback. Step 2: Edit Initial Results
I have list of data that should go to particular website and get some information and write on to the excel but how do I handle exception that in list one of the search data is not available and my code is stopped and giving error as no such element found
In the toggle example if element not displayed it returns false but the in child selection example it throws no such element exception for is displayed () how can this be please clarify
Just some feedback, the s3 link for the first part was not completely loading in my browser. I suspect other things were going on behind the scenes like ad tracker cookies being installed. The script was timing out. As soon as I clicked X next to URL bar to stop the page from continuing to load, the script was able to successfully execute
Also because is_displayed() returns an exception when the element is not found in the DOM, isn't it best practice to encapsulate the code in a try except block so your script does not fail and can instead print a console message that an element is not found.
this is my solution for the hidden elements, you can use my coding: elem1 = driver.find_elements(By.XPATH,"//select[@class='ageselect']") if len(elem1) == 0: print("Element is not in DOM") if len(elem1) > 0 and elem1[0].is_displayed()==False: print("Element is in DOM but not displayed") use elem1 to save all result of finding web element - If cannot find age element in DOM -> print message "Element is not in DOM" instead of error log - If can find age element in DOM but it is not displayed -> print message "Element is in DOM but not displayed"
Not a bad way to put it. I made it work this way: try: age_select = driver.find_element(by=By.XPATH, value="//select[@class='ageselect']") print('Element is in the DOM') except NoSuchElementException: print('ELement is not in the DOM')
@@restoreupscale1521 i have a question, are there any way to access hidden elements ? I try to send email by selenium by python but i dont know the way to open the message box because they are no longer in DOM. I am learning Python from automate the boring stuff book.
Wow, you're not even going to answer how to handle the exception? You're going to give Brasil a heart but ignore the most important question, how to handle the false display... This video is pointless.
this video is exactly what I was looking for and it was very well explained. thank you for sharing; I appreciate your generosity!
thanks a lot this subject took SO LONG for me to finally figure out THANKS SO MUCH MAY ALLAH GIVES YOU THE BEST
I am glad it helped you. Thank you!
It would have been good if you have covered explaining how to handle that exception. This video seems incomplete without handling the exception.
yes that was the actual issue!
elem1 = driver.find_elements(By.XPATH,"//select[@class='ageselect']")
if len(elem1) == 0:
print("Element is not in DOM")
if len(elem1) > 0 and elem1[0].is_displayed()==False:
print("Element is in DOM but not displayed")
you can use this code. use elem1 to save all result of finding web element
- If cannot find age element in DOM -> print message "Element is not in DOM" instead of error log
- If can find age element in DOM but it is not displayed -> print message "Element is in DOM but not displayed"
@@LinhBui-yp8zw I've handled the issue using Nosuchelementexception ... Thank you anyways
Totally! I came here thinking he was going to cover that
Thank you from Brazil. (Y)
If you time for a question, I would appreciate some guidance. I have been trying for days (not kidding) to locate the second Accordion Item in a Python-Dash dbc.Accordion. The html code also has a "flex" badge so I assume it uses flexbox as well. There just is not much documentation at all. I have tried every selector, every path and I can't make it happen. I am posting the code below just in case you can help. I get error messages mostly telling me it cant click at the given coordinates.
I know this question is a shot in the dark. But I am at that point.
Thank you in advance for any feedback.
Step 2: Edit Initial Results
I have list of data that should go to particular website and get some information and write on to the excel but how do I handle exception that in list one of the search data is not available and my code is stopped and giving error as no such element found
In the toggle example if element not displayed it returns false but the in child selection example it throws no such element exception for is displayed () how can this be please clarify
Just some feedback, the s3 link for the first part was not completely loading in my browser. I suspect other things were going on behind the scenes like ad tracker cookies being installed. The script was timing out. As soon as I clicked X next to URL bar to stop the page from continuing to load, the script was able to successfully execute
Also because is_displayed() returns an exception when the element is not found in the DOM, isn't it best practice to encapsulate the code in a try except block so your script does not fail and can instead print a console message that an element is not found.
how do you script negative tests on selenium python?
Thanks.
You're welcome.
Keep watching for more videos!
but man how can I handle this error if the element in not anymore in the DOM? you didn't explain that. I want to verify with Seleniums' asserts
I am getting popup on the page .how to handle it?
this is my solution for the hidden elements, you can use my coding:
elem1 = driver.find_elements(By.XPATH,"//select[@class='ageselect']")
if len(elem1) == 0:
print("Element is not in DOM")
if len(elem1) > 0 and elem1[0].is_displayed()==False:
print("Element is in DOM but not displayed")
use elem1 to save all result of finding web element
- If cannot find age element in DOM -> print message "Element is not in DOM" instead of error log
- If can find age element in DOM but it is not displayed -> print message "Element is in DOM but not displayed"
Not a bad way to put it.
I made it work this way:
try:
age_select = driver.find_element(by=By.XPATH, value="//select[@class='ageselect']")
print('Element is in the DOM')
except NoSuchElementException:
print('ELement is not in the DOM')
@@restoreupscale1521 i have a question, are there any way to access hidden elements ? I try to send email by selenium by python but i dont know the way to open the message box because they are no longer in DOM. I am learning Python from automate the boring stuff book.
@@restoreupscale1521 You have to import from selenium.common.exceptions import NoSuchElementException
Wow, you're not even going to answer how to handle the exception? You're going to give Brasil a heart but ignore the most important question, how to handle the false display... This video is pointless.
For exception handeling check previous python for testers tutorials .