[![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]
-
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?IAmMilinPatel– IAmMilinPatel2023年02月07日 06:21:55 +00:00Commented Feb 7, 2023 at 6:21
-
it does display.Carl Carl– Carl Carl2023年02月07日 06:23:29 +00:00Commented 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.IAmMilinPatel– IAmMilinPatel2023年02月07日 06:26:39 +00:00Commented 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– Carl Carl2023年02月07日 06:52:08 +00:00Commented 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.IAmMilinPatel– IAmMilinPatel2023年02月07日 06:55:23 +00:00Commented Feb 7, 2023 at 6:55
2 Answers 2
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)
-
The solution not work again...Carl Carl– Carl Carl2023年02月09日 05:41:30 +00:00Commented Feb 9, 2023 at 5:41
-
oh god..Will communicate in channel most probably in d evening todayNarendra Chandratre– Narendra Chandratre2023年02月09日 10:04:03 +00:00Commented Feb 9, 2023 at 10:04
-
No prob. will discuss in the channel later.Carl Carl– Carl Carl2023年02月10日 04:24:30 +00:00Commented Feb 10, 2023 at 4:24
-
@CarlCarl No response, I hope issue got resolved for youNarendra Chandratre– Narendra Chandratre2023年02月16日 13:25:26 +00:00Commented Feb 16, 2023 at 13:25
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:
- use actions to click
- get aactive element
- 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 .
-
Do u mean by use the outerhtml to find the element and click on it?Carl Carl– Carl Carl2023年02月08日 15:00:19 +00:00Commented Feb 8, 2023 at 15:00
-
@CarlCarl outerHTML prints the full element tag , so you know what is the currently active elementPDHide– PDHide2023年02月10日 05:06:22 +00:00Commented Feb 10, 2023 at 5:06
-
Yea, i did it, and located the html elements from it but not working.Carl Carl– Carl Carl2023年02月10日 05:29:09 +00:00Commented Feb 10, 2023 at 5:29