0

HTML snapshot:

enter image description here

Hi I want press the button labelled log in on this page, the html for the button is as follows:

<button class="">Log In</button>

the problem is there is multiple log in buttons on the same page with this code so I want to specify this button by using the id of the container the button is in:

<li id  = 'bs-bk-PP" class = "_2t6uLu"

How do I find and click the log in button using these properties. Thanks

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

1 Answers1

-1

To click on the element with text as Log In you can use either of the following Locator Strategies:

  • Using xpath:

    driver.find_element(By.XPATH, "//li[@id='bs-bk-PP']//button[@class and text()='Log In']").click()
    

Ideally, 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 XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@id='bs-bk-PP']//button[@class and text()='Log In']"))).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
  • Thanks but this selects the wrong log in button on the page. How do I include the id for the correct container as per my initial question ? – Eglantine46 Jan 31 '21 at 19:51
  • @Eglantine46 Can you update the question with the text based complete HTML of the element including it;s parent elements? – undetected Selenium Jan 31 '21 at 19:54
  • Can you see the screenshot of the html code in the question? I am unable to select all the html code as it is contained inside different Divs, is it possible to first select the element using the ID = bs-bk-PP then from that element click the log in button using "//button[@class and text()='Log In']" as you mentioned above? – Eglantine46 Jan 31 '21 at 20:27
  • @Eglantine46 Checkout the updated answer and let me know the status – undetected Selenium Jan 31 '21 at 20:33