0

[![first page][1]][1]

from selenium import webdriver  
    import time
    from selenium.webdriver.common.keys import Keys  
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import random
    import select
    
    driver = webdriver.Chrome('ChromeDriver')
    driver.get("https://devbusiness.tunai.io/login")
    time.sleep(2)
    driver.maximize_window()
    
    #log in credentials
    username = driver.find_element(By.NAME, "loginUsername");
    username.send_keys("xxxxx");
    
    password = driver.find_element(By.NAME, "loginPassword");
    password.send_keys("xxxxx");
    
    login = driver.find_element(By.XPATH,"//*[@id='app']/div/div/div/div/div/div[2]/form/div[4]/button");
    login.submit();
    time.sleep(3)
    
    driver.get("https://devbusiness.tunai.io/dashboard/my_salon_user")
    time.sleep(3)
    
    randomUsername = random.choice(["dayon.salon3@tunai","dayonmanager@tunai","Dayon.der@tunai"])
    driver.find_element(By.XPATH, "//tbody[@role='rowgroup']/tr[@role='row']/td/a[text()='"+ randomUsername +"']").click()
    print("Username selected: ", randomUsername)
    time.sleep(5)
    
    driver.find_element(By.XPATH,"//*[@id='page-content']/div/div[3]/div/div[2]/div/div/div[2]/div/div[1]/header/a").click()
    time.sleep(5)
    
    # Get the list of elements
    elements = driver.find_elements(By.CLASS_NAME,'custom-control-input')
    
    # Select a random element from the list
    random_element = random.choice(elements)
    driver.execute_script("arguments[0].click();", random_element)

    # Click on the selected element
    random_element.click()
    print("Element selected: ", random_element)
    time.sleep(5)
    
    driver.find_element(By.XPATH,"//*[@id='accKey']").click()
    time.sleep(5)

I've been add "argument.click[]","webdriver wait until EC to be clickable" but still showing "Element not interactable. What would be the other possible solution? Hope someone could clarify for me. Thanks and have a nice day.

[![second page][2]][2]

10
  • When the page loads, does the element display in the visible portion of the page? or does a user need to scroll down to view it? Commented Feb 7, 2023 at 6:21
  • it does display.
    – Carl Carl
    Commented Feb 7, 2023 at 6:23
  • Is there any frame or an element that overlaps your target element? Or maybe the page loader is still displaying while your script is looking for the element to perform the action. Try waiting till the page loads completely and then click your target element. Commented Feb 7, 2023 at 6:26
  • It is a pop up page, I have set the delay to 10s but same errors thrown...
    – Carl Carl
    Commented Feb 7, 2023 at 6:52
  • Pop-up as in, is it within an iFrame or an <object></object> frame? If so you first need to switch to that frame and then try to access and interact with your target element. Commented Feb 7, 2023 at 6:55

2 Answers 2

1

Solution :

  • To iterate from list and have a random element to be clicked on
  • Snippet
    elements = []

    # Get the list of elements
    elements = driver.find_elements(By.XPATH, "//div[@class='custom-control custom-switch mt-2 mb-2']")
    size = len(elements)
    for element in elements:
     if element:
      element_to_be_clicked = elements[random.randint(0, len(elements))]
      element_to_be_clicked.click()
    print("Permission Selected:-", elements)
    time.sleep(3)
4
  • The solution not work again...
    – Carl Carl
    Commented Feb 9, 2023 at 5:41
  • oh god..Will communicate in channel most probably in d evening today Commented Feb 9, 2023 at 10:04
  • No prob. will discuss in the channel later.
    – Carl Carl
    Commented Feb 10, 2023 at 4:24
  • @CarlCarl No response, I hope issue got resolved for you Commented Feb 16, 2023 at 13:25
0

https://w3c.github.io/webdriver/#interactability

A element is determined to be interactable using above checklist . Sometimes we end up in situation where we cannot find the exact interactable element .

One solution would be:

  1. use actions to click
  2. get aactive element
  3. get outerHTML

nodejs :

driver.actions().click(elem)
let elem =driver.switchTo().activeElement()
let elementTagstring  = elem.getAttribute('outerHTML')
console.log(elementTagstring)

the outerHTML shows the element tag and then you can find the attributes to locate it .

3
  • Do u mean by use the outerhtml to find the element and click on it?
    – Carl Carl
    Commented Feb 8, 2023 at 15:00
  • @CarlCarl outerHTML prints the full element tag , so you know what is the currently active element
    – PDHide
    Commented Feb 10, 2023 at 5:06
  • Yea, i did it, and located the html elements from it but not working.
    – Carl Carl
    Commented Feb 10, 2023 at 5:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.