0

Hello everyone forgive I think I can not really explain my problem, I will try again, if they can not understand me very well is that sometimes my English written fails a lot sorry

What I want to try is to automate the access to a web that I leave and link here RUNT

The first part I have solved that is to enter the data to the form and resolve the im not to robot in send

I'm going to post all the code in python

from selenium import webdriver
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 pandas as pd
import threading
import time
import csv
import os


# options = webdriver.ChromeOptions()
# options.add_argument(
#    r'user-data-dir=C:\Users\RADEON\AppData\Local\Google\Chrome\user Data\default')
#
# options.add_extension(r"C:\Users\RADEON\Documents\Web Driver\Selenium\exs.crx")

# driver = webdriver.Chrome(
#    executable_path="C:\\Users\\RADEON\\Documents\\Web Driver\\chrome Driver\\chromedriver.exe",
#    chrome_options=options
# )
#
# driver = webdriver.Firefox()
#
# driver.get("https://www.runt.com.co/consultaCiudadana/#/consultaVehiculo")
# assert "Consulta Ciudadano - RUNT" in driver.title
#
# wait = WebDriverWait(driver, 2)
# wait.until(EC.presence_of_element_located((By.ID, "noPlaca")))
#
#
# wait.until(EC.presence_of_element_located((By.ID, "noPlaca")))


class Runt:

    def __init__(self, placa, nit, time):
        self.placa = placa
        self.nit = nit
        self.options = webdriver.ChromeOptions()
        self.options.add_extension(
            r"C:\Users\RADEON\Documents\Web Driver\cp.crx")

        self.driver = webdriver.Chrome(
            chrome_options=self.options)

        self.wait = WebDriverWait(self.driver, time)
        self.wait_API = WebDriverWait(self.driver, 150)

    def closeBrowser(self):
        self.driver.close()

    def run(self):

        driver = self.driver
        wait = self.wait
        wait_api = self.wait_API
        driver.get("https://www.runt.com.co/consultaCiudadana/#/consultaVehiculo")

        wait.until(EC.presence_of_element_located((By.ID, "noPlaca")))
        placa = driver.find_element_by_id('noPlaca')
        placa.clear()
        placa.send_keys(self.placa)

        wait.until(EC.presence_of_element_located((By.NAME, "noDocumento")))
        owner = driver.find_element_by_name('noDocumento')
        owner.clear()
        owner.send_keys(self.nit)

        # /html/body/div[1]/div/div[1]/div[2]/div[1]/div[2]/div[7]/div[1]

        wait_api.until(EC.presence_of_element_located((
            By.XPATH, "//*[@id='captcha']/div/div[2]/a[1]")))

        while (driver.find_element_by_xpath("//*[@id='captcha']/div/div[2]/a[1]").get_attribute("innerText") != "Solved"):
            print("Search Solution....")
        print("solution found...")

        if(driver.find_element_by_xpath("//*[@id='captcha']/div/div[2]/a[1]").get_attribute("innerText") == "Solved"):
            driver.find_element_by_xpath(
                "/html/body/div[1]/div/div[1]/div[2]/div[1]/div[2]/div[1]/div[3]/div[2]/div/div/form/div[8]/button").click()

        WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
            (By.CSS_SELECTOR, "div.panel.panel-default>div.panel-heading>h4.panel-title a"))).click()

        vigente = driver.find_element_by_xpath(
            "//*[@id='pnlRevisionTecnicoMecanicaNacional']/div/div/div/table/tbody/tr[1]/td[5]")

        print(vigente.get_attribute("innerText"))


runt2 = Runt("aqd470", 63364079, 2)
# runt1 = Runt("aqd470", 45884847, 2)
#
# thread1 = threading.Thread(target=runt1.run)
thread2 = threading.Thread(target=runt2.run)
#
# thread1.start()
thread2.start()
# r'C:\Users\RADEON\Documents\Web Driver\csv.csv'

Ignore the threads was doing some tests.

When running this program on the aforementioned web waiting to solve the I am not a robot and send the form, and the code appears that I want to get the information

but the information does not appear in the html until clicking on the following div

<div class="panel-heading" ng-click="togglePanel('pnlRevisionTecnicoMecanicaNacional');
                        consultarDetalle('RevisionTecnicoMecanicaNacional')">
                        <h4 class="panel-title">
                            <i class="i_hoja s_25_o1 ib"></i>
                            <a> Certificado de revisión técnico mécanica y de gases (RTM)</a>
                        </h4>
                    </div>

U can use this example data to enter "AFD329" For Nplaca,"6656954" For Documento

The other fields can be left as default I need to click on that element to load the rest of the query would appreciate a lot if you can help me

5
  • driver.find_element_by_xpath( "/html/body/div[1]/div/div[1]/div[2]/div[1]/div[2]/div[7]/div[1]/h4/a").click() Commented Nov 15, 2018 at 3:19
  • it could be dynamic html, can you post url of the page? Commented Nov 15, 2018 at 4:10
  • which element you want to interact ? Commented Nov 15, 2018 at 5:07
  • Hello everyone forgive I think I can not really explain my problem, I will try again, if they can not understand me very well is that sometimes my English written fails a lot sorry link Commented Nov 16, 2018 at 0:59
  • @ArKaDiA Update the question with the Manual Steps you are trying to Automate and the error stack trace (if any) Commented Nov 16, 2018 at 5:45

2 Answers 2

1

Based on your xpath you are locating the <a> under <h4>.

Element may required some time to get visible, for that try explicitwait until element get visible.

Import below packages :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

Try with below code :

element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((CSS_SELECTOR, ".panel-title a")))
element.click()

Its bad practice to use absolute xpath, use relative xpath instead. or try CSS Selector over the xpath.

Sign up to request clarification or add additional context in comments.

Comments

0

@NarendraR's answer was in the right direction.

As per your question and the HTML you have provided, the attribute ng-click is applied to the <div> node which is generally not clickable. So instead of attempting to click the ancestor <div> node you need to invoke the click() on one of it's descendant node i.e. the <a> node.

Again as the element is an Angular element you need to induce WebDriverWait and you can use either of the following solutions:

  • Using PARTIAL_LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Certificado de revisión técnico mécanica y de gases"))).click()
    
  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.panel.panel-default>div.panel-heading>h4.panel-title a"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='panel-heading']/h4[@class='panel-title']//a[contains(.,'Certificado de revisión técnico mécanica y de gases')]"))).click()
    
  • 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
    

1 Comment

DebanjanB Thank you for your help but it does not work I understand what you mention to me, I appreciate your help expand the question to give you more information

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.