0

I want to click a three way toggle using selenium with python.The html element Ids are dynamic. So I have tried with an XPath where class contains a specific text! But I seeing 'element not found'/'element not visible' whole day!

I've tried with below line of code but no help.

browser.find_element_by_xpath("//*[contains(@class,'switch switch-three toggle ios') and contains(text(),'Available')]").click()

Here is the HTML code of the page and I want to click on - 'Available'

<label class="switch switch-three toggle ios" id="radio8526" onclick="" style="float: left; width: 300px; height:15px; margin-right: 20px;margin-left: 20px;">          
    <input id="available8526" value="available" onclick="setVersioningIdFun('8526');document.getElementById('toggleStateButton').click();;" name="onoffswitch8526" type="radio">                    
        <label for="available8526" onclick="">Available</label>
    <input id="unavailable8526" value="unavailable" onclick="setVersioningIdFun('8526');document.getElementById('toggleStateButton').click();;" name="onoffswitch8526" type="radio">
        <label for="unavailable8526" onclick="">Unavailable</label>
    <input id="archived8526" value="archived" onclick="setVersioningIdFun('8526');document.getElementById('toggleStateButton').click();;" name="onoffswitch8526" type="radio" checked="">
        <label for="archived8526" onclick="">Finalised</label>
<a class="slide-button"></a>
</label>

2 Answers 2

1

From w3c documentation You can use this to solve your problem

browser.find_element_by_css_selector('input[id^="available"]').click()
Sign up to request clarification or add additional context in comments.

9 Comments

Tried But confronted with below error again! selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
You can try debugging to see if its finding the element without clicking it, there might be the chance that the element we are trying to click is the not visible and that's why its not clickable.There might be other elements like <label> or <a> that will receive the click.
I think label is the element that is clickable , can you please try this and confirm browser.find_element_by_css_selector('label[for^="available"]').click()
Tried but no help.
If nothing works then your last stop would be javascript executor . You can use the onclick values [onclick="setVersioningIdFun('8526');document.getElementById('toggleStateButton').click();] and execute them with the help of javascript executor.
|
0

You can just use the value attribute, e.g.

input[value='available']

You might need to add a wait for clickable to make sure the page has loaded. See this link for more info and some examples.

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.