0
I’m trying to write in a textbox and click on a button (these elements are initially hidden in the page) using Selenium (with Java), but I can’t find the element, I’ve tried searching for name, ID, tagname, classname, Xpath, I can’t manipulate in any way.
Follow screen print with inspect active elements.
What happens is that for this textbox and button to appear on the screen I need to click the request button (until that part I can):
Here the elements I mentioned are active:
In the code below I got the amount of elements that I find on the page that have the same id, name, tagname, classname or Xpath textbox that I want to manipulate (the first 2 lines is to press the request button, this part is working):
That is, in all forms of manipulating the textbox return that there is no such element (except classname, but of these 10 found elements none is the textbox that I want to manipulate, I have tested one by one).
As this page is part of a local portal of the company where I work, it is no use to pass a link to check, so I sent several prints.
Does anyone know any way to deal with these Hidden elements?
Caio, this code would be to manipulate IE right? You could do this by manipulating Chrome? Anything I try to translate my code to manipulate IE and test this idea.
– Murillo Carvalho
I tried using this code: Webelement txb =driver.findElement(By.name("_Justification")); jse.executeScript("Arguments[0].click();", txb); .
– Murillo Carvalho
This code works for any browser, I believe! I even always use Firefox and never had problem, it is not to have headache with Chrome too. In relation to this error, it occurs because the element is hidden, and Selenium tries to find the Webelement anyway. What I imagine to be feasible and work, is what I posted in the answer, which would be a javascript "injection". Try to use it exactly like it is there, and give me an answer to see if it worked!
– Caio
Now I did it. I realized that the textbox and the button were inside an iframe, and while searching the internet I saw that I had to use "driver.switchTo(). frame(0);" in order to be able to write to it. Javascript failed because it could not find any element with the name or id I passed.
– Murillo Carvalho
I get it. great that you solved it! You can also switch to the frame by passing its ID as argument, if you need to, and for ease of viewing as well.
– Caio
Thank you so much for your help. In my case it would not be right to go by ID or Name because these identifiers are not fixed in my iframe, each time I run the program they change, so I had to choose the index.
– Murillo Carvalho