0

Selenium WebDriver Python

Please refer to the image below:

enter image description here

In this image we have a link which on click will open popup window to enter data: But the problem is that this link is not clickable with selenium WebDriver. What I have tried?

  • Adding wait by using WebDriverWait and then clicking element.
  • (data-yjs-datasource-url="/legals/add") copying Url from this attribute and appending it to the base url. This opens the add liability page in new windows but on new page "Save" button is not available, like you can write data in the form but there is no way to save those changes

I need help on how to click on this button and open a popup in the same window and then enter the data. Is there any way through which I can retrieve the yjs based form as a popup in same window?

DebanjanB
  • 118,661
  • 30
  • 168
  • 217

1 Answers1

0

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

  • Using css_selector:

    driver.find_element(By.CSS_SELECTOR, "ul.dropdown-menu.dropdown-menu-right > li > a[data-yjs-datasource-url='/legals/add']").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//ul[@class='dropdown-menu dropdown-menu-right']/li[@class]/a[@data-yjs-datasource-url='/legals/add']").click()
    

The desired element is a dynamic element, so 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 CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.signin-btn.sbLoginBtn > span.btf-text"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//ul[@class='dropdown-menu dropdown-menu-right']/li[@class]/a[@data-yjs-datasource-url='/legals/add']"))).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
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217