I have a textbox in the footer of the pagination table. This textbox contains a textbox with up and down arrows as shown in the below Image. This textbox values will dynamically changed when we click on next, previous buttons.
Image URL: http://i.msdn.microsoft.com/dynimg/IC1380.jpg
This is the input from DOM
<div ng-grid-footer="" class="ng-scope"><div ng-show="showFooter" class="ngFooterPanel ng-scope ui-widget-content ui-corner-bottom" ng-class="{'ui-widget-content': jqueryUITheme, 'ui-corner-bottom': jqueryUITheme}" ng-style="footerStyle()" style="width: 1920px; height: 55px;">
<div class="ngTotalSelectContainer">
<div class="ngFooterTotalItems ngNoMultiSelect" ng-class="{'ngNoMultiSelect': !multiSelect}" style="margin-top: 8px">
<span class="ngLabel ng-binding">Total Items: 810</span><span ng-show="filterText.length > 0" class="ngLabel ng-binding ng-hide">(Showing Items: 100)</span>
</div>
<div class="ngFooterSelectedItems ng-hide" ng-show="multiSelect">
<span class="ngLabel ng-binding">Selected Items: 0</span>
</div>
</div>
<div class="ngPagerContainer ngNoMultiSelect" style="float: right; margin-top: 10px" ng-show="enablePaging" ng-class="{'ngNoMultiSelect': !multiSelect}">
<div style="float:left; margin-right: 10px" class="ngRowCountPicker">
<span style="float: left; margin-top: 8px" class="ngLabel ng-binding">Page Size:</span>
<select style="float: left;height: 29px; width: 100px" ng-model="pagingOptions.pageSize" class="ng-valid ng-dirty">
<!-- ngRepeat: size in pagingOptions.pageSizes --><option ng-repeat="size in pagingOptions.pageSizes" class="ng-scope ng-binding" value="10">10</option><!-- end ngRepeat: size in pagingOptions.pageSizes --><option ng-repeat="size in pagingOptions.pageSizes" class="ng-scope ng-binding" value="25">25</option><!-- end ngRepeat: size in pagingOptions.pageSizes --><option ng-repeat="size in pagingOptions.pageSizes" class="ng-scope ng-binding" value="50">50</option><!-- end ngRepeat: size in pagingOptions.pageSizes --><option ng-repeat="size in pagingOptions.pageSizes" class="ng-scope ng-binding" value="100">100</option><!-- end ngRepeat: size in pagingOptions.pageSizes -->
</select>
</div>
<div style="float:left; margin-right: 10px; line-height:25px" class="ngPagerControl">
<button class="ngPagerButton" ng-click="pageToFirst()" ng-disabled="cantPageBackward()" title="First Page"><div class="ngPagerFirstTriangle"><div class="ngPagerFirstBar"></div></div></button>
<button class="ngPagerButton" ng-click="pageBackward()" ng-disabled="cantPageBackward()" title="Previous Page"><div class="ngPagerFirstTriangle ngPagerPrevTriangle"></div></button>
<!--Input Textbox Which I want to Inspect -->
<input class="ngPagerCurrent ng-valid-number ng-valid-min ng-valid ng-valid-max ng-dirty" min="1" max="9" type="number" style="width:50px; height: 26px; margin-top: 1px; padding: 0 4px" ng-model="pagingOptions.currentPage">
<!--END-->
<button class="ngPagerButton" ng-click="pageForward()" ng-disabled="cantPageForward()" title="Next Page"><div class="ngPagerLastTriangle ngPagerNextTriangle"></div></button>
<button class="ngPagerButton" ng-click="pageToLast()" ng-disabled="cantPageToLast()" title="Last Page"><div class="ngPagerLastTriangle"><div class="ngPagerLastBar"></div></div></button>
<button ng-controller="OmniSearchViewCtrl" id="page-summary-help-button" title="Help" class="ngPagerButton ng-scope" ng-click="handlePageSummaryHelpButtonClick()">
<span class="ptipsicon ptipsicon-help" style="padding:0 6px; float:left"></span>
</button>
</div>
</div>
This is Xpath
//*[#id="PageViewContainer"]/div/div[3]/div/div[2]/div[2]/input
My problem is, I am unable to get the values from the textbox since the textbox doesn't have any attribute:value. I have tried using the below lines to get the text but it just displays a blank. However, I didn't get any exceptions
pageNumber = findElement(By.xpath(properties.getString("PageNumber"))).getText();
pageNumber = findElement(By.xpath(properties.getString("PageNumber"))).getAttribute("value");
Whereas, when I tried this I am getting no such element found exception.
pageNumber = findElement(By.xpath("//input[#id=\"PageViewContainer\"]"))).getText();
Any help would be much appreciated.
//*[#id="PageViewContainer"]
Your xpath begins with a search for an element with an id="PageViewContainer". There is no such element in your HTML, so your xpath returns nothing.
Based on the snippet you have given, you can find the input element by:
//div[#class='ngPagerControl']/input
You can then use the getText() method to extract the text value.
Related
I have a page where I need to extract the text from an xpath and the status of the radio or checkbox that is associated with the text.
Each element is contained in a class called "c-form-group", so i have written a loop to iterate through to extract the "Text" the will be 4 elements found on the page. But it is failing on element 3 & 4, i must have something wrong with my xpath. I have yet to add in the check for the checkbox/radio button,
The first two elements are returning the values i require, then fails on element3.
Here are the 4 text elements i am trying to extract:
Plan B Warranty (Taxi) & Breakdown Recovery
Vehicle Asset Protection - Standard Cover
Negative Equity Cover
You confirm that you have received the VAP key facts leaflet?
Here is the code for the loop.
WebElement elem = driver.findElement(By.className("c-form-group"));
System.out.println("a");
List<WebElement> elementz = elem.findElements(By.xpath("//label[contains(#class,'c-option')]"));
for(int i = 0 ; i< elementz.size() ; i++){
System.out.println("Loop : " + i);
String vapval1 = elementz.get(i).findElement(By.xpath("//label[#class='c-option c-option--right u-px u-py-sm u-clearfix ng-scope' and not(#class='ng-pristine ng-untouched ng-valid ng-valid-required') and not (#class='c-option__radio')]")).getText();
System.out.println("0 = " + vapval1);
String vapval2 = elementz.get(i).findElement(By.xpath("//label[#class='c-option c-option--right u-px u-py-sm u-clearfix' and not(#class='ng-pristine ng-untouched ng-valid ng-valid-required') and not (#class='c-option__radio')]")).getText();
System.out.println("1 = " + vapval2);
String vapval3 = elementz.get(i).findElement(By.xpath("//label[#class,'c-option c-option--right u-px u-py-sm u-clearfix ng-scope' and not(#class='ng-pristine ng-untouched ng-valid') and not (#class='c-option__checkbox')]")).getText();
System.out.println("3 = " + vapval3);
String vapval4 = elementz.get(i).findElement(By.xpath("//label[#class,'c-option c-option--right u-px u-py-sm u-clearfix' and not(#class='ng-pristine ng-untouched ng-valid ng-valid-required') and not (#class='c-option__checkbox')]")).getText();
System.out.println("4 = " + vapval4);
}
Here is the full html, which may help.
<!DOCTYPE html>
<html class="ng-scope" ng-app="dan">
<head>
<body class="u-scroll-y ng-scope" ng-controller="CoreController as cc">
<div class="c-animate c-animate--show u-pos-f-t ng-hide" ng-show="global.alerts.length">
<div class="o-grid-fluid u-h-100 u-pl-0">
<div class="o-grid__row u-ml-0 u-h-100">
<div class="c-loader ng-hide" ng-show="loadingHome" style="">
<nav class="o-grid__col-xl-2 o-grid__col-lg-3 o-grid__col-xs-4 u-p-0 c-card__block u-h-100 u-shadowed u-pos-f-t ng-scope" ng-if="global.loggedIn">
<div class="u-p-0 u-h-100 o-grid__col-xl-10 o-grid__col-lg-9 o-grid__col-xs-8 u-pull-right" ng-class="{ 'o-grid__col-xl-10 o-grid__col-lg-9 o-grid__col-xs-8 u-pull-right' : global.loggedIn }">
<header class="o-layout-table__row u-bg-primary u-shadowed u-clearfix u-px ng-scope" ng-if="global.loggedIn">
<main class="o-view-container">
<div class="o-grid-fluid u-py-md">
<div class="o-grid__row">
<div class="c-animate c-animate--view-slide-in-right c-animate--view-slide-out-right ng-scope" ng-view="" style="">
<div class="o-grid__col-md-10 o-grid__col-xl-8 o-grid__col-xl-offset-2 o-grid__col-md-offset-1 ng-scope">
<div class="u-mb-lg u-text-center">
<h1 class="u-text-bold">Recommendations</h1>
</div>
<form class="ng-valid ng-valid-min ng-valid-max ng-valid-required ng-dirty ng-valid-parse" name="recommend" ng-submit="recommend.$valid" style="">
<div class="o-media c-card c-card__block u-shadowed u-mb-lg ng-scope" ng-if="rc.WarrantyEligible && !rc.prevWarranty()">
<label class="c-form-control-label u-px u-py-sm u-w-100">Warranty Options:</label>
<div class="c-form-group u-p-0 u-mb-sm u-clearfix">
<div class="o-grid__col-md-8">
<label class="c-form-control-label u-text-normal">Product Recommendations (Years):</label>
</div>
<div class="o-grid__col-md-4">
<input class="c-form-control ng-pristine ng-untouched ng-valid ng-valid-min ng-valid-max ng-valid-required" required="" placeholder="Years" ng-model="rc.recommend.year" min="1" max="3" type="number">
</div>
</div>
<div class="c-form-group ng-scope" ng-if="data.answer_taxi">
<label class="c-option c-option--right u-px u-py-sm u-clearfix ng-scope" ng-if="!rc.planA && !rc.prestige" ng-click="cc.utils.audit('recommendation_warranty_plan_taxi_b')">
<input class="ng-pristine ng-untouched ng-valid ng-valid-required" required="" ng-model="rc.recommend.warrantyPlan" value="taxiB" name="warrantyPlan" type="radio">
<i class="c-option__radio"></i>
Plan B Warranty (Taxi) & Breakdown Recovery
</label>
</div>
</div>
<div class="o-media c-card c-card__block u-shadowed u-mb-lg u-text-body u-bg-success" ng-if="!rc.prevVap() && rc.VapEligible ">
<div class="c-form-group">
<label class="c-form-control-label u-px u-py-sm u-w-100">Vehicle Asset Protection Options:</label>
<label class="c-option c-option--right u-px u-py-sm u-clearfix" ng-click="cc.utils.audit('recommend_vap')">
<input class="ng-pristine ng-untouched ng-valid ng-valid-required" required="" ng-model="rc.recommend.vapPlan.plan" value="standard" name="vapPlan" type="radio">
<i class="c-option__radio"></i>
Vehicle Asset Protection - Standard Cover
</label>
<label class="c-option c-option--right u-px u-py-sm u-clearfix ng-scope" ng-if="data.answer_equity == true" ng-click="cc.utils.audit('recommend_negative_equity')">
<input class="ng-untouched ng-valid ng-dirty ng-valid-parse" ng-model="rc.recommend.vapPlan.equity" name="vapPlanEquity" type="checkbox" style="">
<i class="c-option__checkbox"></i>
Negative Equity Cover
</label>
<label class="c-option c-option--right u-px u-py-sm u-clearfix" ng-click="cc.utils.audit('vap_key_facts_checked')">
<input class="ng-pristine ng-untouched ng-valid ng-valid-required" required="" ng-model="rc.recommend.vapCheck" name="vapCheck" type="checkbox">
<i class="c-option__checkbox"></i>
You confirm that you have received the VAP key facts leaflet?
</label>
</div>
</div>
</form>
<div class="c-form-group">
</div>
</div>
</div>
</div>
</main>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js">
<script src="./build/app.js?v=2.13" defer="">
<script src="/build/standalone/jspdf.js" defer="">
<script src="/build/standalone/sigWebTablet.js" defer="">
</body>
</html>
I'm a little confused as to what you are trying to do. You mention getting the text from the elements and also getting the state of the checkboxes. Your XPaths on the outer and inner loop overlap. Your elementz list is pulled from a LABEL that contains the c-option class but then you start with an element from elementz and the first part of your XPath you repeat the search for a LABEL that contains the c-option class.
There is an much easier way to do this. Each of these checkboxes/radiobuttons are INPUT tags and have a name specific to their value.
Plan B Warranty (Taxi) & Breakdown Recovery: <input ... name="warrantyPlan" type="radio">
Vehicle Asset Protection - Standard Cover: <input ... name="vapPlan" type="radio">
Negative Equity Cover: <input ... name="vapPlanEquity" type="checkbox" style="">
You confirm that you have received the VAP key facts leaflet?: <input ... name="vapCheck" type="checkbox">
So with that info, you can just get each INPUT with CSS selectors like
By.cssSelector("input[name='warrantyPlan']")
Once you have the INPUT element, you can check if it's selected using .isSelected().
If you really do need the text, you can get the label because it's the parent of the INPUT we just got. We can do this with an XPath, By.xpath(".."), which gets the parent of the current element.
We can put this all together like
// Plan B Warranty (Taxi) & Breakdown Recovery
WebElement e = driver.findElement(By.cssSelector("input[name='warrantyPlan']"));
System.out.println(e.isSelected()); // false
System.out.println(e.findElement(By.xpath("..")).getText()); // Plan B Warranty (Taxi) & Breakdown Recovery
// Vehicle Asset Protection - Standard Cover
e = driver.findElement(By.cssSelector("input[name='vapPlan']"));
System.out.println(e.isSelected()); // false
System.out.println(e.findElement(By.xpath("..")).getText()); // Vehicle Asset Protection - Standard Cover
I just did the first two. You can see the pattern and apply it for the last two.
I've tried below code :
Select dropdown = new Select(driver.findElement(By.xpath("//a[contains(text(),'--None--')]")));
dropdown.selectByIndex(1);
Getting below error :
Exception in thread "main"
org.openqa.selenium.support.ui.UnexpectedTagNameException: Element
should have been "select" but was "a"
This is my full DOM structure :
<div class="compoundTLRadius compoundTRRadius compoundBorderBottom form-element__row uiMenu" data-aura-rendered-by="2600:0" data-aura-class="uiMenu">
<div id="2574:0" data-aura-rendered-by="2581:0" class="uiPopupTrigger" data-aura-class="uiPopupTrigger" data-interactive-uid="19">
<div data-aura-rendered-by="2583:0"><div data-aura-rendered-by="2576:0">
<a aria-required="false" class="select" aria-disabled="false" aria-haspopup="true" tabindex="0" role="button" aria-label="Salutation" title="" href="javascript:void(0);" data-aura-rendered-by="2577:0" data-interactive-lib-uid="45">--None--</a>
</div>
</div>
</div>
<div class="select-options popupTargetContainer uiPopupTarget uiMenuList uiMenuList--default uiMenuList--left uiMenuList--short" data-aura-rendered-by="2595:0" data-aura-class="uiPopupTarget uiMenuList uiMenuList--default uiMenuList--left uiMenuList--short" aria-labelledby="2574:0"><div class="select-options" role="menu" data-aura-rendered-by="2589:0"><!--render facet: 2590:0-->
<ul class="scrollable" role="presentation" data-aura-rendered-by="2591:0" data- scoped-scroll="true"><!--render facet: 2592:0--></ul>
</div></div></div>
I want code for locating dropdown icon and select a first value from that.
This is a screen shot of my webpage
Here is the html code
<div class="slimScrollDiv" style="position: relative; overflow: hidden; width: auto; height: 350px;"><div class="scroller" style="height: 350px; overflow: hidden; width: auto;" data-always-visible="1" data-rail-visible1="0" data-handle-color="#D7DCE2">
<div class="tsk-row clearfix">
<div class="tsk-left">
New task to check new build of 2016.4.18.1
</div>
test
<div class="tsk-right">
<span class="label label-warning">Assigned</span>
</div>
</div>
<div class="tsk-row clearfix">
<div class="tsk-left">
test 2
</div>
test
<div class="tsk-right">
<span class="label label-warning">Assigned</span>
</div>
</div>
<div class="tsk-row clearfix">
<div class="tsk-left">
test
</div>
test
<div class="tsk-right">
<span class="label label-warning">Assigned</span>
</div>
</div>
<div class="tsk-row clearfix">
<div class="tsk-left">
New login page
</div>
test
<div class="tsk-right">
<span class="label label-warning">Assigned</span>
</div>
</div>
<div class="tsk-row clearfix">
<div class="tsk-left">
new task
</div>
Ongoing
<div class="tsk-right">
<span class="label label-warning">Assigned</span>
</div>
</div>
<div class="tsk-row clearfix">
<div class="tsk-left">
This is testing
</div>
test
<div class="tsk-right">
<span class="label label-warning">Assigned</span>
</div>
</div>
</div>
</div><div class="slimScrollBar" style="width: 7px; position: absolute; top: 0px; opacity: 0.4; display: none; border-radius: 7px; z-index: 99; right: 0px; height: 300.245px; background: rgb(0, 0, 0);"></div><div class="slimScrollRail" style="width: 7px; height: 100%; position: absolute; top: 0px; display: none; border-radius: 7px; opacity: 0.2; z-index: 90; right: 0px; background: rgb(51, 51, 51);"></div></div>
Here is my automation test case
public void openAllTask() throws InterruptedException{
List<WebElement> task=driver.findElements(By.cssSelector(".tsk-row.clearfix")); // get the list of total no of elements present in the task window
System.out.println("size of i loop "+task.size());
for(int i=1; i<=task.size(); i++){
//find the element one by one using xpath
System.out.println(driver.findElement(By.xpath("html/body/div[2]/div[3]/div/div/div/div[3]/div/div[1]/div["+i+"]/div[1]/a")).getText());
driver.findElement(By.xpath("html/body/div[2]/div[3]/div/div/div/div[3]/div/div[1]/div["+i+"]/div[1]/a")).click();
Thread.sleep(3000);
driver.navigate().back();
Thread.sleep(3000);
// find the scroll bar and move the scroll bar by cirten pixles
WebElement element=driver.findElement(By.xpath("html/body/div[2]/div[3]/div/div/div/div[3]/div/div[2]"));
Actions act=new Actions(driver);
act.dragAndDropBy(element, 0, (i*10)).build().perform();
Thread.sleep(3000);
}
I want to select each element from the window which is highlighted and also scroll the window down so that when dynamically elements are added then I can scroll down and read all the elements.
Try like below:
//i am not sure about my css path is correct or not as no way to check it
// if it prints the text and size correctly, than it will fine but if not than please give the right css path.
List<WebElement> elements = driver.findElements(By.cssSelector(".tsk-row.clearfix > div.tsk-left> a");
System.out.println("size is "+elements.size());
for(int i = 0; i < elements.size(); i++){
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement elem = elements.get(i);
//this line will scroll down to make element visible
js.executeScript("window.scrollTo(" + elem.getLocation().x + "," +(elem.getLocation().y- 100) + ");");
//don't use this kind of wait, use explicit wait
Thread.sleep(1000);
System.out.println(elem.getText());
elem.click();
Thread.sleep(3000);
driver.navigate().back();
Thread.sleep(3000);
}
Hi I was wondering if i could use this command when there is no ID field, it seems like the button accepts input. I tried .sendKeys but it doesn't seem to do anything, places said don't use the .click(); command after.
Here is the html for the button.
<button class="md-button-icon mt-toolbar-button md-button md-default-theme ng-pristine ng-untouched ng-valid" accept="image/*" ng-model="chatFiles" ng-disabled="!sessionStarted" ng-show="!chatMessage" ng-file-select="" tabindex="0" style="overflow: hidden;" aria-hidden="false" aria-invalid="false" aria-disabled="false">
<mt-icon class="ng-isolate-scope" height="24" width="24" icon=" attachment" style="width: 24px; height: 24px;">
<span>menu</span>
<input type="file" accept="image/*" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;" tabindex="-1" ng-file-generated-elem="true">
</button>
This is my code in webdriver:
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div[2]/div/md-card/md-content/div/div[2]/button[2]")));
WebElement Upload = driver.findElement(By.xpath("/html/body/div[2]/div/md-card/md-content/div/div[2]/button[2]"));
Upload.sendKeys("C:/Users/elsid/Desktop/Eclipse/Workspace/NG - Mentored/Autoit/test.png");
This is the code from the uploaded image all the way down to the button again.
<li class="ng-scope mt-chat-mine" layout="row" ng-class="{ 'mt-chat-mine': message.isMine()}" ng-repeat="message in messages">
<!--
ngIf: !message.isMine()
-->
<!--
ngIf: message.type == 1
-->
<!--
ngIf: message.type == 2
-->
<img class="chat-image ng-scope" ng-if="message.type == 2" ng-src="http://mentoredapp.perrysysdev.com/usercontent/SessionFiles/8040eeaa-3584-4a13-b54e-a16bfadd6433.jpg" src="http://mentoredapp.perrysysdev.com/usercontent/SessionFiles/8040eeaa-3584-4a13-b54e-a16bfadd6433.jpg"></img>
<!--
end ngIf: message.type == 2
-->
<!--
ngIf: message.type == 3
-->
<!--
ngIf: message.isMine()
-->
<img class="avatar ng-scope" ng-if="message.isMine()" ng-src="http://mentoredapp.perrysysdev.com/usercontent/TutorProfilePictures/25f586a2-5031-49a5-94a3-e65305faed8a.png" src="http://mentoredapp.perrysysdev.com/usercontent/TutorProfilePictures/25f586a2-5031-49a5-94a3-e65305faed8a.png"></img>
<!--
end ngIf: message.isMine()
-->
</li>
<!--
end ngRepeat: message in messages
-->
</ul>
<div class="text-box" layout="row">
<textarea id="chat-message-box" class="message-box ng-pristine ng-untouched ng-valid" placeholder="Send a message.." ng-disabled="!sessionStarted" mt-enter="sendChatMessage()" flex="" ng-model="chatMessage" aria-multiline="true" tabindex="0" aria-invalid="false" aria-disabled="false"></textarea>
<button class="md-button-icon mt-toolbar-button md-button md-default-theme ng-hide" ng-transclude="" ng-show="chatMessage" ng-disabled="!chatMessage" ng-click="sendChatMessage()" tabindex="0" aria-hidden="true" aria-disabled="true" disabled="disabled"></button>
<button class="md-button-icon mt-toolbar-button md-button md-default-theme ng-valid ng-dirty ng-valid-parse ng-touched" accept="image/*" ng-model="chatFiles" ng-disabled="!sessionStarted" ng-show="!chatMessage" ng-file-select="" ng-click="clicked" tabindex="0" style="overflow: hidden;" aria-hidden="false" aria-invalid="false" aria-disabled="false">
<mt-icon class="ng-isolate-scope" height="24" width="24" icon=" attachment" style="width: 24px; height: 24px;"></mt-icon>
<span></span>
<input type="file" accept="image/*" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;" tabindex="-1" ng-file-generated-elem="true"></input>
</button>
You can simplify the xpath little bit more to find the element easily
By xpath = By.xpath("//span[text()='menu']");
By fileTag = By.cssSelector("[type='file']");
wait.until(ExpectedConditions.presenceOfElementLocated(xpath)));
WebElement Upload = driver.findElement(fileTag);
Upload.sendKeys("C:/Users/elsid/Desktop/Eclipse/Workspace/NG - Mentored/Autoit/test.png");
If the file input is hidden only way to handle that is JavaScript and set the attribute. Try the following code
String filePath = "C:/Users/elsid/Desktop/Eclipse/Workspace/NG - Mentored/Autoit/test.png";
String script = "document.querySelector(\"[type='file']\").setAttribute('value','" + filePath + "');";
((JavascriptExecutor)driver).executeScript(script);
I assumed that's the only file input tag on that page and not hidden. If not you may have to adjust the file selector
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
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+"]"));