2

Sorry if there was an answer for this already, i'm new to programming and all of this, and tried researching the issue but am unable to find a solution. Also sorry in advance if i'm not adhering to proper etiquette or post formatting.

My main issue right now is that I am trying to use selenium + Python to automatically input credentials into https://cloud.tenable.com/tio/app.html#/login.

The problem i am running into is that my script is unable to find the actual username and password fields to input the credentials. I've tried inspecting the HTML for those fields, but the ID is hidden. I tried using the xpath for that field and i'm getting an error saying that the element is unable to be located.

Here is what I've got so far:

# Python/Selenium program log into tenable and export pdf report

# import webdriver

from selenium import webdriver
from selenium.webdriver.common.by import By

# create webdriver object
driver = webdriver.Firefox()
# get tenable website
driver.get("https://cloud.tenable.com/tio/app.html#/login")

# Credentials test
username = "username test"
uname = driver.find_element(By.XPATH,'//*[@id="main-app"]/div[1]/div/div/div[1]/div/form/div[1]/div/div/div[1]/input')
uname.send_keys("username")

I've tried using the xpath that chrome's developer console provided me, I've tried using the xpath that the SelectorsHub extension in chrome provided me, but nothing is working. I just want to be able to automate exporting a report from the website, but my first hurdle is just trying to log in. I've read about something called iframes and possibly using WebDriverWait, but i'm not sure if that applies to this situation or not due to my lack of experience. Any assistance would be greatly appreciated!!

2 Answers2

0

It is unlikely that the whole page has loaded between driver.get(...) and driver.find_element(...). Try adding a sleep between these lines to verify this.

from time import sleep

driver = webdriver.Firefox()
driver.get("https://cloud.tenable.com/tio/app.html#/login")
time.sleep(5) # make it longer if needed

# Credentials test
username = "username test"
uname = driver.find_element(By.XPATH,'//*[@id="main-app"]/div[1]/div/div/div[1]/div/form/div[1]/div/div/div[1]/input')
uname.send_keys("username")

If that works, you can use WebDriverWait to wait for the elements to load.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
timeout = 10
xpath = '//*[@id="main-app"]/div[1]/div/div/div[1]/div/form/div[1]/div/div/div[1]/input'
uname = WebDriverWait(driver, timeout).until(EC.visibility_of_element_located((By.XPATH, xpath)))
uname.send_keys('username')
Francis Godinho
  • 195
  • 1
  • 9
0

To send a character sequence within the Username and Password field ideally you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    driver.get(url='https://cloud.tenable.com/tio/app.html#/login')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='username']"))).send_keys("TotallyClueless")
    driver.find_element(By.CSS_SELECTOR, "input[name='password']").send_keys("TotallyClueless")
    
  • Using XPATH:

    driver.get(url='https://cloud.tenable.com/tio/app.html#/login')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "element_xpath"))).send_keys("TotallyClueless")
    driver.find_element(By.XPATH, "//h2[@class='product-title ui-product-title']").send_keys("TotallyClueless")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser snapshot:

TotallyClueless

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352