Article 55B7J Selenium: Check whether button exist or not and if exist whether the the text is in it is desired one or not

Selenium: Check whether button exist or not and if exist whether the the text is in it is desired one or not

by
daichiash
from LinuxQuestions.org on (#55B7J)
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 messageAnother tried solution:
Code:if len(if(!driver.find_element(By.CSS_SELECTOR,"")) > 0:
driver.find_element_by_css_selector("").click()
else:
print messageBut 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.latest?d=yIl2AUoC8zA latest?i=Fct3zg87crs:EowoXrGwF4c:F7zBnMy latest?i=Fct3zg87crs:EowoXrGwF4c:V_sGLiP latest?d=qj6IDK7rITs latest?i=Fct3zg87crs:EowoXrGwF4c:gIN9vFwFct3zg87crs
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments