Home > Blockchain >  I have the same ID for three different xPath, i can only use one of them, the others doesn't wo
I have the same ID for three different xPath, i can only use one of them, the others doesn't wo

Time:07-28

#IMPORTS

from lib2to3.pgen2 import driver
import subprocess, sys
def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
    install("selenium")
    install("chromedriver_autoinstaller")

#Imports
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.by import By
import chromedriver_autoinstaller


chromedriver_autoinstaller.install()

navegador = webdriver.Chrome()
navegador.get("https://auth.idwall.co/v2")

navegador.find_element("xpath", '//*[@id="__next"]/div[1]/div/button').click()
    
navegador.find_element("xpath", '//*[@id="__next"]/form/div/div/div/div[2]/div/div/div/input').send_keys(codigo1)
    
navegador.find_element("xpath", '//*[@id="__next"]/form/div/div/button').click()

[enter image description here][1]

Only the firs line works, the rest doesn't, how can i get it to work? please, explain very detailed, i am a newbie.

**The error i encounter is:** selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="__next"]/form/div/div/button"}

i don't think you guys are going to be able to enter the part i am currently stuck cause its going to need the credencials. Thanksss.

https://i.stack.imgur.com/0i7BA.png

CodePudding user response:

I suggest that you find the element by its class name. Kindly try:

from selenium.webdriver.common.by import By

And then:

navegador.find_element(By.CLASS_NAME,"NumberInput_pinInput__qUJlu").send_keys(codigo1)

CodePudding user response:

I think you need to define a clear Xpath for all the elements you want to access.
Try this script:

driver.get("https://auth.idwall.co/v2")
WebDriverWait(driver,timeout=10).until(EC.visibility_of(driver.find_element(by=By.XPATH,value="//input[@id='user-email']")))
driver.find_element(by=By.XPATH,value="//input[@id='user-email']").click() #optional step
driver.find_element(by=By.XPATH, value="//input[@id='user-email']").send_keys("your_username")
driver.find_element(by=By.XPATH,value="//input[@id='user-password']").click() #optional step
driver.find_element(by=By.XPATH, value="//input[@id='user-password']").send_keys("your_password")
driver.find_element(by=By.XPATH, value="//button[text()='Entrar']").click()

Note: The script is in English and Selenium 4. You can make use of the locators though and write it in your own format.

  • Related