1

Im trying to find the username path for the login page on https://www.textnow.com/login. I've tried finding it by x_path, ID, Name, class but my bot just cant find it. Does anyone have any possible solutions that I would be able to try out ?

Source Code:

"SUDO FUNCTION: OPEN A NEW TAB FOR TEXT NOW AND LOG IN"
driver.implicitly_wait(3)
driver.execute_script("window.open('http://www.textnow.com/login','new window')")

textNowEmail = driver.find_element_by_id('txt-username')# still have not found username textfield 
textNowEmail.send_keys(textNowUser)

#Set password code 
textNowPass = driver.find_element_by_id('txt-password')
textNowPass.send_keys('fill')

This is the message im getting:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="txt-username"]"}
  (Session info: chrome=78.0.3904.108)
Guy
  • 46,488
  • 10
  • 44
  • 88
  • show your code (as text, not image). Don't expect that we will write all from scratch. Do you get error message when you run it in console/terminal/cmd.exe ? Show full error message as text (not image) in question (not in comment) – furas Dec 08 '19 at 20:27
  • I had no problem to put username and password in form. Show your code and then we can explain what wrong with code. – furas Dec 08 '19 at 20:34
  • whats wrong with it ? i can clearly see `id="txt-username"` over there. Would you add relevant code. – Nik Dec 09 '19 at 04:56
  • I edited the post so you can see my source code guys –  Dec 09 '19 at 05:41

3 Answers3

0

You are opening a new window. Are you switching to it ? To make sure you are on the right window you can get page source by using "driver.get_source()" method and then evaluate the DOM.

Considering there are 2 window handles, you can switch to newly opened window using following :

required_window = driver.window_handles[1]
driver.switch_to_window(required_window)

Also try using "WebDriverWait" and "expected_conditions" to wait till required element is present by importing following:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

and then finding element using expected conditions:

WebDriverWait(driver,5).until(
         EC.presence_of_element_located((By.ID, "txt-username")))
Ayaz
  • 249
  • 1
  • 2
  • 11
0

When you are opening new window with execute_script your window handle is still in the original window. You need to switch window.

You can check all the windows available with driver.window_hanldes

For your case just use

driver.switch_to.window(driver.window_handles[1])

after opening new window

then proceed with rest of your code

megamind
  • 627
  • 9
  • 17
0

To send a character sequence to the Email or Username and Password fields with in the website https://www.textnow.com/login you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://www.textnow.com/login")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.uikit-text-field__input#txt-username"))).send_keys("Xavier-Uriel-Espinal")
    driver.find_element_by_css_selector("input.uikit-text-field__input#txt-password").send_keys("Xavier-Uriel-Espinal")
    
  • Using XPATH:

    options = webdriver.ChromeOptions() 
    options.add_argument("start-maximized")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://www.textnow.com/login")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='uikit-text-field__input' and @id='txt-username']"))).send_keys("Xavier-Uriel-Espinal")
    driver.find_element_by_xpath("//input[@class='uikit-text-field__input' and @id='txt-password']").send_keys("Xavier-Uriel-Espinal")
    
  • Note : You have to add the following imports :

    from selenium import webdriver
    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:

textnow

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