1

I have 2 websites that i would like to automate search process, and i am struggling of finding a way to locate and fill elements and speed up the process(as i use these websites many times a day): http://pretraga2.apr.gov.rs/ObjedinjenePretrage/Search/Search http://www.nbs.rs/internet/english/67/rir.html

I tried almost everything, and managed to locate the text field "Матични број:" on the first website, but when trying to fill it i get element not visible exception. The second site i tried triggering javascript but it opens the form for search in new window, and the search cant be made from there.

Hopefully someone will come up with some kind of solution, thanks in advance.

milorads
  • 51
  • 1
  • 11
  • How are you identifying the element? Probably the selector you are using is incorrect – Saifur Sep 20 '15 at 21:58
  • Welcome to Stack Overflow! Please read the guide [How do I ask a good question](http://stackoverflow.com/help/how-to-ask), especially the part on Minimal, Complete, and Verifiable example (MCVE). This will help you solve problems for yourself. If you do this and are still stuck you can come back and post your MCVE, what you tried, and what the results were so we can better help you. – JeffC Sep 20 '15 at 23:03

2 Answers2

2

There are exactly two elements with same id and names. If you carefully investigate you will see the second element is the one you want.

td.apr-mbr>[name='SearchByRegistryCodeString']

Edit:

This code works just fine on first link.

WebElement element = driver.findElement(By.cssSelector("td.apr-mbr>[name='SearchByRegistryCodeString']"));
        element.sendKeys("Test");

enter image description here

Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Thanks for the answer, i have located it but when i try to send keys to it it gives me the element not visible exception.. I can post the code i used... edit: List frameList=driver.findElements(By.className("SearchTable")); WebElement a = frameList.get(1); List st1=a.findElements(By.className("apr-mbr")); WebElement test11 = st1.get(1); WebElement testuno = test11.findElement(By.xpath("//input")); System.out.println(testuno.getAttribute("id")); and the id matches the one i inspect, but still cant acess the box.. – milorads Sep 20 '15 at 22:31
  • @b02 You are doing too much unnecessary work. See my edit – Saifur Sep 20 '15 at 22:49
  • Thanks a bunch mate, you made it so easy, i guess i need to look up into css selectors and xpaths a bit more, makes it a lot easier than what i used :) should i use similar solution to the second website ? – milorads Sep 20 '15 at 23:08
  • What are looking for in second website? – Saifur Sep 20 '15 at 23:13
  • To fill registration number text field and hit Search button.. But this one has javascript that loads the form, i tried executing it but it opens useless form in new window. – milorads Sep 20 '15 at 23:17
  • @b02 simply use `name` or `[name='matbr']` as cssSelector – Saifur Sep 20 '15 at 23:33
  • org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[name='matbr']"} i guess im doing it wrong, sorry if im being boring :) – milorads Sep 20 '15 at 23:35
  • @b02 Actually the element is inside an `iframe` and so you need to use `switchTo()` method to switch to iframe. The following code works just fine `driver.switchTo().frame(0); WebElement element = driver.findElement(By.cssSelector("[name='matbr']")); element.sendKeys("Test");` – Saifur Sep 20 '15 at 23:40
0

this can also happen occasionally when the element is not visible without scrolling (but I don't know exactly why although the element in my case not is hidden) I found the solution is to move the focus to the element before call the action required (click,sendKeys, etc)

Actions actions = new Actions(driver);
actions.moveToElement(webElement).perform();