Selenium click a button if the parameter is true
<p>I wanted to create a function which takes a parameter and if the parament is True then the button is click otherwise no. Can i use this?</p>

<pre><code>def buttonClick(self, Button):
    if Button == True:
        self.driver.find_element_by_id('button').click
</code></pre>

<p>Two main things to fix from the top of my head:</p>

<ul>
<li>you can avoid having <code>== True</code> part</li>
<li>you are not calling the <code>click</code> method - add the <code>()</code></li>
</ul>

<p>Fixed version:</p>

<pre><code>def buttonClick(self, should_click_button):
    if should_click_button:
        self.driver.find_element_by_id('button').click()
</code></pre>

<p>Sample usage:</p>

<pre><code>instance = MyClass()
instance.buttonClick(True)
instance.buttonClick(False)
</code></pre>

<p>You can also set the default value for the argument:</p>

<pre><code>def buttonClick(self, should_click_button=False):
    if should_click_button:
        self.driver.find_element_by_id('button').click()
</code></pre>

<p>Now, if you don't need to click the button, simply don't pass the argument:</p>

<pre><code>instance = MyClass()
instance.buttonClick(True)
instance.buttonClick()
</code></pre>

python selenium