I want to check whether a button exist in page or not. And if exist to check whether the button text is submit or anything else. And if exist then click it while if it does not exist or if text is not submit then print a message.
What i have tried:
Code:
if(!driver.find_element(By.CSS_SELECTOR, "").isEmpty()){
driver.find_element_by_css_selector("").click()
}
else{
print message
Another tried solution:
Code:
if len(if(!driver.find_element(By.CSS_SELECTOR,"")) > 0:
driver.find_element_by_css_selector("").click()
else:
print message
But it was throwing following exception error instead of clicking or printing message.
Code:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
This happens only with script
However when i was doing scraping in interactive python mode than button is found immediately on loading website and is clicked by both xpath and css.
But when i use it in script it always give this error of element not found.
I have also tried setting timeout, thinking that element might be loading slowly but same problem.
Also i tried waiting with expected conditions but same error.
This error occurs only when i use python script for automation and not when i implement same steps in interactive mode.