i have written a sample code in selenium using python language and i encountered with some problem didn't get any solution
in the web, and my problem is in selenium i have kept one validation if object is available then go to next line other wise get out
from there, but selenium is keep on waiting for that object if the object is not present other wise it is returning true value and
executing fine..my requirement is if the object is not available get out from there and return false..
i have written code like this
try:
element = driver.find_element_by_id("DateOfBirthD")
elementfound=element.is_displayed()
if elementfound==True:
print "element found"
else:
print "element not found"
except:
print "no element"
try:
element = WebDriverWait(driver, 2000).until(EC.presence_of_element_located((By.ID, "DateOfBirthD")))
#do something
except:
print "element not found"
In the above two types if the element is found it is working fine and going to next line but if the element is not found it is waiting for long time till the element is found as we know there is no element
please find me a solution to how to validate the objects in selenium
The amount of time that you want it to wait is specified in seconds. In your case, you are telling it to wait 2000 seconds before continuing.
You can read about it at the official docs: http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.