Challenge: Click on buttons with complex HTML structures in Python Selenium
Question:
A user encountered challenges locating and clicking buttons with the following HTML structure:
<code class="html"><div class="b_div"> <div class="button c_button s_button" onclick="submitForm('mTF')"> <input class="very_small" type="button"> <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"> <span>Reset</span> </div> </div></code>
Attempted Solutions:
The user tried using various Selenium selectors, such as:
However, they received NoSuchElementException errors.
Solution:
To fix the issue, the user needed to remove spaces between class names in the CSS selector. The correct selectors are:
<code class="python">driver.find_element_by_css_selector('.button.c_button.s_button').click()</code>
The above is the detailed content of How to Click Complex Buttons with Nested HTML Structures Using Python Selenium?. For more information, please follow other related articles on the PHP Chinese website!