LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 07-03-2020, 10:17 AM   #1
daichiash
LQ Newbie
 
Registered: Jun 2020
Posts: 2

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


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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How To Install Selenium and Chrome On Centos 7 LXer Syndicated Linux News 0 01-18-2020 04:25 AM
Script to check PID from file and check whether process is running or not rajkiran183 Linux - Newbie 5 10-19-2012 11:28 AM
Nagios - Selenium: check for file content and compares with specified threshold Cr45h Linux - Server 4 07-19-2012 03:43 AM
Check whether a .zip exist or not xombboxer Linux - Newbie 3 04-08-2012 12:17 PM
Mutlipe text/button form, one submit button bappreacher Programming 8 06-27-2006 08:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 01:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration