Mar-12-2024, 12:39 PM
Hi! I'm new to Python programming and trying to create a POC for my project.
Goal:
1) Find all elements on the webpage(present inside and outside table grids)
2) Count the number of elements
3) Categorize as text fields, buttons, checkboxes, dropdowns
4) If input type = text fields AND disabled= false, create a for loop and enter sequentially 1,2,3...
5) If input type = checkbox AND disabled= false, select it
6) If input type = dropdown AND disabled= false, select first value
Currently, I'm stuck at step 1. when I'm trying to find all webelements, I'm getting a huge list with all <td> which do not have a specific attribute to filter on and categorize for step 2. Please help with a simple solution, if there exists any.
Below is the I'm trying:
import selenium.webdriver.common.devtools.v121.fed_cm
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from urllib3.util import url
from webdriver_manager.chrome import ChromeDriverManager
'''Navigate to *** template'''
driver.find_element("xpath", "/html/body/div/div[3]/ul/li[1]/a").click()
driver.find_element("xpath", "/html/body/div/div[3]/ul/li[1]/ul/li[2]/a").click()
driver.find_element("xpath", "//table//a[text()= 'AIS Import']").click()
'''Click on the first template(should be AUTO:..'''
links = driver.find_elements("xpath", "//table//a")
links[0].click()
'''Start creating ***'''
driver.find_element("xpath", "//*[@id='job_reference']").send_keys("21")
# FIND FUNCTION TO WRITE TO ALL 'TD' ELEMENTS FROM TABLE
ais_links = driver.find_elements("xpath", "//table[@id='table_no_size']//td")
count = 0
for link in ais_links:
count += 1
print(link.get_attribute("innerHTML"))
print(count)
Goal:
1) Find all elements on the webpage(present inside and outside table grids)
2) Count the number of elements
3) Categorize as text fields, buttons, checkboxes, dropdowns
4) If input type = text fields AND disabled= false, create a for loop and enter sequentially 1,2,3...
5) If input type = checkbox AND disabled= false, select it
6) If input type = dropdown AND disabled= false, select first value
Currently, I'm stuck at step 1. when I'm trying to find all webelements, I'm getting a huge list with all <td> which do not have a specific attribute to filter on and categorize for step 2. Please help with a simple solution, if there exists any.
Below is the I'm trying:
import selenium.webdriver.common.devtools.v121.fed_cm
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from urllib3.util import url
from webdriver_manager.chrome import ChromeDriverManager
'''Navigate to *** template'''
driver.find_element("xpath", "/html/body/div/div[3]/ul/li[1]/a").click()
driver.find_element("xpath", "/html/body/div/div[3]/ul/li[1]/ul/li[2]/a").click()
driver.find_element("xpath", "//table//a[text()= 'AIS Import']").click()
'''Click on the first template(should be AUTO:..'''
links = driver.find_elements("xpath", "//table//a")
links[0].click()
'''Start creating ***'''
driver.find_element("xpath", "//*[@id='job_reference']").send_keys("21")
# FIND FUNCTION TO WRITE TO ALL 'TD' ELEMENTS FROM TABLE
ais_links = driver.find_elements("xpath", "//table[@id='table_no_size']//td")
count = 0
for link in ais_links:
count += 1
print(link.get_attribute("innerHTML"))
print(count)