Skip to content
Advertisement

I can’t get element on PHP website with Selenium

I need to build a script to automate action on this website that is builded using PHP.

For that, I’m using the Selenium package for python.

So I instantiate the browser and made login using the xpath to get the elements

JavaScript

The problem

After log-in on the page, I need to click on a input type=”button”, so I’m trying to get the element using xpath again.

JavaScript

but the following exception was raised.

JavaScript

What I already tryed

I tryed to get the element using full x-path and id

I also printed the base64 image after loging to check if the page was updating and it is.

IMAGE OF PAGE HTML

enter image description here

Update

I looked at some other questions and I found this, so I tried to run the following code, but a TimeoutException was raised.

JavaScript

Update 2

JavaScript

this code crashed on the product_import line, so, apparently, the driver switched to the correct iframe, but selenium.common.exceptions.NoSuchElementException: was raised

SOLUTION

I used chromium to get full xpath of two frames that was wrapping my application (I discovered that by getting the full xpath of my button and I see that was too short, that because he was wrapped).

So I ran the following code

JavaScript

If the button was actually a button and not an input type button he could be click by using this command.

JavaScript

Advertisement

Answer

The input tag is in iframe, in Selenium you will have to switch to iframe first and then you can interact with the input tag.

Please switch it like this :

JavaScript

You will have to import these :

JavaScript

You will also have to make sure that the input is under just this iframe. There could be a possibility of nested iframes as well.

Also, iframe id has to be unique in HTMLDOM to make this to work.

PS : Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.

Also, I would say if id is unique please use id not xpath for this :

JavaScript

A way better approach would be with WebDriverWait element_to_be_clickable. Something like this :

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement