Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I am new to python selenium and I am trying to click on a button which has the following Html structure:

<div class="b_div">

    <div class="button c_button s_button" onclick="submitForm('mTF')">

        <input class="very_small" type="button"></input>

        <div class="s_image"></div>

        <span>

           Search

        </span>

    </div>

    <div class="button c_button s_button" onclick="submitForm('rMTF')" style="margin-bottom: 30px;">

        <input class="v_small" type="button"></input>

        <span>

              Reset

        </span>

   </div>

</div>

I would like to be able to click both the Search and Reset buttons above (obviously individually).

I have tried a couple of things, for example:

driver.find_element_by_css_selector('.button .c_button .s_button').click()

or,

driver.find_element_by_name('s_image').click()

or,

driver.find_element_by_class_name('s_image').click()

but, I seem to always end up with NoSuchElementException, for example:

selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate element: {"method":"name","selector":"s_image"}' ;

I am wondering if I can somehow use the onclick attributes of the HTML to make selenium click?

Any thoughts which can point me in the right direction would be great. Thanks.

1 Answer

0 votes
by (62.9k points)

Remove space between classes in CSS selector:

driver.find_element_by_css_selector('.button.c_button.s_button').click()

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s online Selenium course

Browse Categories

...