1

I'm new to Selenium. I have been looking all the ways possible to resolve this problem (at this point I think it is just unsolvable) I have a web page (can't share) with this input:

/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[3]/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div/iframe/#document/html/body/div[2]/div/iframe/#document/html/frameset/frame/#document/html/frameset/frameset/frameset/frame/#document/html/body/div/form/table/tbody/tr[2]/td[2]/input

(As you can see the structure has a mix of frames, iframes and framesets; some of them have id and other names some none)

The problem is that Selenium will not find the element by any method I have tested

. First I tried with a simple driver.findElement(By.all of them)

After they didn't work I start looking on the web and I couldn't find why I couldn't get a handle of this.

It is the only input in the web page and has an id as attribute, so it should be easy.

This is the class where I have been trying to make it work, If you want to check my unsuccessful work I focused my last efforts on the attempt number 8.

As you can see I have been trying to obtain it by several ways, the frames really seemed an issue but it was not them, nor the waiting.

Is it really no way of getting this element? Is it one of those cases where Selenium can't automate? Or it is that I'm missing something.

object IS visible and there is not even a scroll bar, the whole page fits in the screen perfectly, Xpath was one of the first choices I tested, didn't work

Thank you in advance.

White_King
  • 748
  • 7
  • 21
  • 4
    Share your HTML. – Ratmir Asanov Feb 25 '19 at 13:53
  • 1
    `iframe`s can mess things up because they are webpages embedded in webpages. And you have multiple of them unfortunately. Please look at [this article](https://www.guru99.com/handling-iframes-selenium.html) on how to switch to the correct iframe before you select the element by id. – AutomatedChaos Feb 25 '19 at 14:10
  • I'm sorry Ramtir I know you can't help me like you want but I cant share the HTML :S. And regarding to the iframe topic, what the article proposed is one of my approaches at the code sample that I published. Didn't worked either. @AutomatedChaos – White_King Feb 26 '19 at 05:11
  • 1
    This [answer](https://stackoverflow.com/a/15471734) describes switching to first frame (iframe) and then child frame (iframe) within it. This [answer](https://stackoverflow.com/a/37742837) explains that you can ignore framesets, just work with frames therein. So trying to work through your code example and assuming the frames are nested and not siblings have you tried: `util.driver.switchTo().frame("contentAreaFrame") util.driver.switchTo().frame("isolatedWorkArea") util.driver.switchTo().frame("0") util.driver.switchTo().frame("0") util.driver.findElement(By.xpath(//input))` – elworthy Feb 27 '19 at 15:09
  • I think that is what I'm doing on line: 264, but trying exactly with what you are suggesting gave me this error: org.openqa.selenium.NoSuchFrameException: No frame element found by name or id isolatedWorkArea. Although I started debugging and after a lot of try I figured out that SELENIUM was switchingTo another frame with another name! even when I was looking for the exact name Selenium was messing it around so I used By.xpath to switch to the frame and it finally worked Thank you guys. – White_King Mar 02 '19 at 11:13

2 Answers2

0

I don't know if this is the problem, but is the element you trying to use visible or you need to scroll in order to view it? If it's not visible try using this to scroll a little bit :

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,1000)");

Another possible solution is to try use the absolute xpath instead of relative. There are several tools to find the absolute xpath of an element in an html page. Then you can use

driver.findElement(By.xpath(absoluteXpath));
Thanos M
  • 604
  • 6
  • 21
  • No, the object IS visible and there is not even a scroll bar, the whole page fits in the screen perfectly, Xpath was one of the first choices I tested, didn't work. I tried with several, you can see some it in the code I published thank you though :( – White_King Feb 26 '19 at 05:06
0

After a lot of try I realized that selenium was switching to a different frame at the last switchTo. This is probably a bug, but I modified the way I was getting the last switch to to instead of

    var wait = (new WebDriverWait(driver, secsToWait));
    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameNameOrId));

To

    driver.switchTo().frame(driver.findElement(By.xpath("//frame[@"+attribute+"='"+frameNameOrId+"']")));

So it finally worked and obtained the input normally.

White_King
  • 748
  • 7
  • 21