0
votes

element i needed is present in a frame. Code is identifying the frame but not the element present in that frame.

<div id="cod-info" class="lightbox infobox">
<div id="returns-info" class="lightbox infobox">
<div id="lb-coupon-widget" class="lightbox">
<div id="lb-login" class="lightbox loginbox loginsignupV2" data-signupsplashpageload="2">
<div id="lightbox-shim" class="lightbox-shim" style="display: block;"></div>
<iframe id="mklogin-iframe" src="javascript:void(0)" name="mklogin-iframe" style="position: absolute; height: 0px; top: -100px;">-----> Frame
<div class="myntra-tooltip">
<div id="lb-sizechart" class="lightbox lb-sizechart" style="display: block;">
<div class="mod" style="min-height: 478px; margin-top: 20px; margin-bottom: 20px;">
<div class="close"></div>
<div class="loading" style="display: none;"></div>
<div class="hd">
<div class="bd mk-cf">
<div>
<div id="tab-list" class="mk-f-left lft-cont">
<div class="tab-btns">----> Want to locate element present in this div
Code : driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='mklogin-iframe']")));---- to switch to frame

driver.findElement(By.xpath("(//div[@class='tab-btns']/ul/li)["+2+"]"));---> to locate element.

It is showing unable to locate element
1
Are you sure it's in the iframe? If what you posted is the HTML source then it's not. - Robin Green
Hi Robin,Actually one i click on one button a new window is opening above the below window and that up window is in frame only. - naman
I don't think that's relevant. - Robin Green

1 Answers

0
votes

I think you are not waiting for the element to appear,you can try using Explicit Wait...

WebDriverWait wait = new WebDriverWait(driver,60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("selector_of_element")));

Note : 'cssSelector' can be replaced with xpath,id,name,className..etc as per your convinience.

OR

If there are more than one element with the same selector or xpath,you can try the combination of Implicit Wait and findElements...

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
List <WebElement> elements = driver.findElements(By.xpath("(//div[@class='tab-btns']/ul/li)["+2+"]"));