2

when I click on an image manually, the new page loads, and the new page is stable.

When I click via selenium in python, the new page loads for a few seconds and then returns to the previous page automatically for an unknown reason, so I can't capture the elements of the new page.

The first click is on this img:

<span class="option center" id="FXS_edit">
    <img src="../img/edit.png" title="Editar">
</span>

The new page has a table call "extensions_table", and i want to retrive the "value='558131835426'"

<table id="extensions_table" class="form">
                    <thead>
                    <tr>
                    </tr>
                    </thead>
                    <tbody id="kextensionsitemsform">
<tr class="highlight">
  
        <td><input type="checkbox" value="0" checked="">0</td>
        <td><input type="text" value="558131835426" maxlength="15" autocomplete="off"></td>
        <td><input class="user_ext" type="text" value="558131835426"></td>
        <td><input class="pwd_ext" type="password" value="Asd123!."></td>
</tr>

My code:

chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.BinaryLocation = os.getcwd() + os.sep + "chrome.exe" + \
    os.sep + "chrome.exe"

driver = webdriver.Chrome(options=chrome_options)

driver.get("http://login:passwd@IP Address") 

driver.find_element(By.CSS_SELECTOR, "#FXS_edit").click()

sleep(2)

table_id = driver.find_element(By.XPATH,'/html/body/div[1]/div[3]/div/div[5]/fieldset/div[2]/div[1]/div/form/table')
/html/body/div[1]/div[3]/div/div[5]/fieldset/div[2]/div[1]/div/form/table

#or

table_id = driver.find_element(By.ID, "extensions_table")

I get the Message:

NoSuchElementException: Message: no such element: Unable to locate element

cause the new page is not on the screen anymore, it's already returned to the previous page

How do I make the new page stable, just like running the page manually?

I tried different ways to click the img, but the same pattern repeats.

Ajeet Verma
  • 2,938
  • 3
  • 13
  • 24
  • I'm not sure we can answer this question without being able to interact with the target website ourselves. It sounds like the issue is in the behavior of the website. – larsks Jun 03 '23 at 11:51
  • The page is only accessible on the local network, maybe only with a remote access – José Souza Jun 03 '23 at 13:29
  • I could be wrong, I'm just starting to programing, but, If is a issue behavior on the website, why it works when pressed manually – José Souza Jun 03 '23 at 16:04
  • I found out, that the problem is related to the authentication method that i was using. – José Souza Jun 03 '23 at 23:28

1 Answers1

0

I found out, that the problem is related to the authentication method that i was using.

When i access the website an alert box pop up ask for login and password.

I was putting the authentication in the URL when using driver get method.

driver.get("http://login:passwd@IP Address")

I changed that by using pyautogui (click and typewrite) in the authentication alert pop up, and the problem that was happened later on (pages loading and then return to prevous page), after a click on a img, din't happened anymore, i don't really know whats is the relation between the two things.

pyautogui.click(670,188,duration=1)
pyautogui.typewrite("login")
pyautogui.click(673,230,duration=1)
pyautogui.typewrite("password")

I was wondering if there is another way for autheticating on alert pop up, using selenium