0

I am learning Selenium using Python. I have tried to check the button status - whether enabled or not? For that I have used mercury demo site and wrote the below code. I am getting

Unable to locate element: input[value=roundtrip]

Code which I have used:

from  selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Firefox(executable_path="C:\\Seleinum_Python\\WedDriver\\geckodriver.exe")
driver.get("http://newtours.demoaut.com/")
# Whether the user name & password enabled and displayed
user_ele = driver.find_element_by_name("userName")   # <input type="text" name="userName" size="10">
print(user_ele.is_displayed()) # Return True /False based on element status
print(user_ele.is_enabled())
pwd_ele = driver.find_element_by_name("password")   #<input type="password" name="password" size="10">
print(pwd_ele.is_displayed())
print(pwd_ele.is_enabled())
user_ele.send_keys("mercury")
pwd_ele.send_keys("mercury")
driver.find_element_by_name("login").click()
roundtrip_radio= driver.find_element_by_css_selector("input[value=roundtrip]") #<input type="radio" name="tripType" value="roundtrip" checked="">
print(roundtrip_radio.is_selected())
oneway_radio= driver.find_element_by_css_selector("input[value=oneway]")
print(oneway_radio.is_selected())
driver.close()

I even tried with below combination but still I am getting the same element not found issue.

 roundtrip_radio= driver.find_element_by_css_selector("input[value='roundtrip']")
 roundtrip_radio= driver.find_element_by_css_selector('input[value="roundtrip"]')
 roundtrip_radio= driver.find_element_by_css_selector("//input[value='roundtrip']")
 roundtrip_radio= driver.find_element_by_css_selector("input[value='roundtrip']")
 roundtrip_radio= driver.find_element_by_css_selector('input[name="tripType"][value="roundtrip"]')

1 Answer 1

1

In your css selector you can use :checked to identify selected elements.

for example :-

"input[type=radio]:checked"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.