0

I am trying to click a button which un-hides another text box. The button click changes the script from

<span id="incident.u_brand_edit" style="display: none;">

to

<span id="incident.u_brand_edit" style>

Following is the button HTML

<button class="btn btn-default btn-ref" type="button" aria-labelledby="incident.u_brand_title_text" 
data-target="#incident\.u_brand" title="" tabindex="0" id="incident.u_brand_unlock" 
data-type="glide_list_unlock" data-ref="incident.u_brand" data-auto-close="false" 
data-placement="auto" style="margin-right: 5px;" list-read-only="false" 
data-original-title="Unlock Brand"><span class="icon icon-locked" aria-hidden="true"></span></button>

I am trying to achieve this using the following code

driver.find_element_by_id("incident.u_brand_unlock").click()

Also tried this

driver.find_element_by_id("incident.u_brand_unlock").send_keys("\n")

The above codes are focusing on the button but it's not clicking and the text box is not unhiding to perform further operations.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

Try to use the ActionChains class in your code like below -

# Import
from selenium.webdriver import ActionChains

wait = WebDriverWait(driver, 5)
action = ActionChains(driver)

Button_Click = wait.until(EC.element_to_be_clickable((By.ID, 'incident.u_brand_unlock')))
action.move_to_element(Button_Click).click().perform()
Swaroop Humane
  • 1,770
  • 1
  • 7
  • 17
0

To click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-default.btn-ref[id$='u_brand_unlock'][data-original-title='Unlock Brand']>span"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-default btn-ref' and contains(@id, 'u_brand_unlock')][@data-original-title='Unlock Brand']/span"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Found out the answer in this post . Had to remove the style attribute of the field I wanted to appear.