1

I'm using driver.findElement(By.xpath("//a[@title='A K T İ V A S Y O N']")); to locate the element given below in the screenshots but getting Unable to find element error.

enter image description here enter image description here enter image description here enter image description here

There are nested classes and frames also. how can I use switch method for nested frames?

My last try is the following one; Screenshot's attached also.enter image description here

driver.findElement(By.xpath("//frameset[@id='fset1']//frame[@name='ax']//frame[@name='menu']//div[@id='vodaMenuDiv']//li[@id='CCBmain']//li[@id='ccbabone']//li[@id='ccbcquery']//a[@title='A K T İ V A S Y O N']")).click();

Niels van Reijmersdal
32.7k4 gold badges59 silver badges125 bronze badges
asked Apr 15, 2019 at 16:14
3
  • 2
    Check if the element is inside iframe Commented Apr 15, 2019 at 16:15
  • Try xpath using contains text- driver.findElement(By.xpath(".//a[contains(text(),'A K T İ V A S Y O N')]")); Commented Apr 16, 2019 at 5:38
  • You can also try this may this work for you- driver.findElement(By.xpath(".//li[@id='ccbcquery']/a")); Commented Apr 16, 2019 at 5:42

3 Answers 3

0

If you cannot find an element, you need to check if it is inside a frame (or iframe). A frameset is a way to split a window in multiple frames, which acts as a separate window. Selenium needs to switch to this frame first before you can find elements in it.

Your last image shows that the element is within multiple framesets and frames. As frames are not part of the page, but a sort of page on it own you first need to switch to the frame and then to frame within before you can find the element.

Check out some reads:

answered Apr 19, 2019 at 13:20
0

Use below alternatives to locate the element-

driver.findElement(By.xpath("//li[@id='ccbcquery']/a")).click();

equivalent css selector is

driver.findElement(By.cssSelector("li[id='ccbcquery']>a")).click();

OR

driver.findElement(By.cssSelector("li#ccbcquery>a")).click();

Pointed to be noted

  1. Make sure element is not in frame if yes then switch into respective frame using driver.switchTo().frame(frameid/element); and then perform action

  2. Use implicit/explicit wait to get element proper load and available in DOM

    driver.get("web_irl");
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    

    Explicit Wait :

    new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector("li#ccbcquery>a")))).click();
    
answered Apr 16, 2019 at 13:03
2
  • It is about frames (not iframes), voting down to push better answers up. Feel free to edit (and tag me in a comment to vote up again) or delete your answer. Commented Apr 19, 2019 at 13:51
  • @NielsvanReijmersdal, thanks for suggestion, I have updated the answer Commented Apr 29, 2019 at 14:57
0

By using: https://github.com/nick318/FindElementInFrames

You can write:

SearchByFramesFactory searchFactory = new SearchByFramesFactory(driver);
searchFactory.search(() -> driver.findElement(By.xpath("//a[@title='A K T İ V A S Y O N']"))).getElem();

It will find your element across any iframes.

answered Oct 16, 2020 at 20:03
1
  • I believe the good answer would not be just promoting your library but also give a quick guide on how to apply it to address OP's particular issue. Commented Oct 16, 2020 at 22:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.