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("dayon@tunai");

password = driver.find_element(By.NAME, "loginPassword");
password.send_keys("12341234");

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 intractable. What would be the other possible solution? Hope someone could clarify for me. Thanks and have a nice day.

2 Answers 2

0

Solution :

  • Our aim is to click on specific element from list
  • I will be doing it in following way:
    1. I will try to identify the element first
findElement():
  for element_name in randomList:
    if element_name.find("**") != -1:
       element = driver.find_elements(By.IOS_CLASS_CHAIN,(element_name)
    else:
       element = driver.find_elements(By.CLASS_NAME,(element_name))

    # Only return the first element found
    if el:
        return element[0]
    else:
        time.sleep(1)
  return None
  1. After identified element, assert it to see if element exists
element = findElement()
assert element, "{}, element does not exist ".format(element)
  1. Perform actual click event
if element.is_displayed() is False:
   waitForElement(element)
element.click()
9
  • no bro, i wanna random click on random list but it said no attribute "click"
    – Carl Carl
    Feb 2, 2023 at 12:32
  • I am using it on daily basis. This should help to click random element from list. But what I felt you should use either "find_elements_by_ios_class_chain" OR "find_elements_by_ios_predicate" to find element particularly when targeting iOS platform. Give a try and let me know! Feb 2, 2023 at 13:00
  • It is a webpage. u can access to it and take a look.
    – Carl Carl
    Feb 2, 2023 at 13:28
  • Bro, the URL and username is in the code uploaded
    – Carl Carl
    Feb 3, 2023 at 0:59
  • @Carl Still no luck? Feb 7, 2023 at 7:19
0
    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("dayon@tunai");
    
    password = driver.find_element(By.NAME, "loginPassword");
    password.send_keys("12341234");
    
    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 intractable. What would be the other possible solution? Hope someone could clarify for me. Thanks and have a nice day.
5
  • hi bro it returns errors: IndexError: Cannot choose from an empty sequence.
    – Carl Carl
    Feb 3, 2023 at 4:48
  • Are the class names you provided correct? Feb 3, 2023 at 5:05
  • I uploaded the class name of the lists. It shouldn't be wrong. @IAMMilinPatel
    – Carl Carl
    Feb 3, 2023 at 5:09
  • Can you share the HTML that is generated? Feb 3, 2023 at 5:46
  • elements = driver.find_elements(By.CLASS_NAME,'custom-control-input') in this line change 'custom-control-input' to 'custom-control' or 'custom-switch' or 'custom-control custom-switch mt-2 mb-2' and see if it works. Feb 7, 2023 at 6:15

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.