Home > Enterprise >  How to click on the list when it said the list has no attribute "click"
How to click on the list when it said the list has no attribute "click"

Time:02-02

    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
    
    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"])
    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)

driver.find_element(By.XPATH,"//*[@id='accAddPermission']/div/diventer image description hereSo After it select the username, it will pop up this, and i wanna click on the add "restriction", then perform random selection on the list.After clicking on it, the list will be auto saved, and i wanna view the list restriction to see if both of it match.

The Errors shown are AttributeError: 'list' object has no attribute 'click'

These are the list i wanna random select, can be select one, two or all.

CodePudding user response:

The problem is that you have picked an option randomly from the list but haven't used it correctly. The usage random.choice(element) is incorrect.

You can use the below code as a reference for the problem that you are facing. Here //tbody[@role='rowgroup']/tr[@role='row']/td[2]/a is thy xpath for the table cell that contains all username fields (plus some other elements)

randomUsername = random.choice(["dayon@tunai","dayon.salon3@tunai","dayonmanager@tunai"])
driver.find_element(By.XPATH, "//tbody[@role='rowgroup']/tr[@role='row']/td/a[text()='" randonUsername "']").click()

in this first ine, this will first create a variable with a random value from your list. Then it will pass the variable with the randomized option in the xpath for the table cell and click it. A new dialog with "Blocked Permissions" will open

CodePudding user response:

To click on specific username listed on table you need to use unique xpath to click.

After login added this code.

driver.get("https://devbusiness.tunai.io/dashboard/my_salon_user")
time.sleep(3)
randomtext = random.choice(["dayon@tunai","dayon.salon3@tunai","dayonmanager@tunai"])
element = driver.find_element(By.XPATH,"//table[@id='__BVID__74']/tbody//tr//td[2]//a[text()='{}']".format(randomtext))
element.click()
  • Related