I am New to selenium: I have this source and am trying click on a button using xpath with selenium webdriver. This is the button(last line in the html) that am trying to click on:
I use this xpath: "//div[#id='innerBody']/div[4]/div/div/ul/li[3]/button"
and it gives me unable to locate element.
Any idea why and how I should go about it.
<document>
<html class="FullPage" xmlns="http://www.w3.org/1999/xhtml" style="">
<head>
<body class="brand brand-mastwide FullPage no-footer width-hd" style="">
<div id="cboxOverlay" style="display: none;"/>
<div id="colorbox" class="" style="padding-bottom: 2px; padding-right: 2px; display: none;">
<div id="masthead" class="masthead full-width">
<div id="toast-absolute" class="full-width">
<!-- Content -->
<div id="outer-outer" class="with-nav">
<div id="outer-wrapper" class="full-width">
<a name="pageTop"/>
<div class="main-wrapper">
<div class="inner">
<div id="applicationHost">
<div data-bind="router: router" data-view="_App/AppShell" style="" data-active-view="true">
<div class="durandal-wrapper" data-view="_App/Home/HomeShell" style="" data-active-view="true">
<link rel="stylesheet" href="/cache/sf/_App/Home/HomeShell.css"/>
<link rel="stylesheet" href="/cache/sf/css/lib/joyride-2.1.css"/>
<div id="regionMain" class="clear-block with-side with-side-left" data-bind="css:{'clear-block with-side with-side-left': ShowLeftNavigation()}">
<div class="content-pane main">
<div class="inner-content-pane main">
<div data-bind="compose: Message"/>
<div class="router" data-bind="router: router">
<div class="durandal-wrapper" data-view="_App/Home/Filebox/Filebox" style="" data-active-view="true">
<h1 data-bind="text: Title">Bestandsvak voor satish vanahalli</h1>
<link href="/cache/f69bb3f534fb459062226526576bc4dea7e8fe7e/css/lib/jqui/jquery-ui-1.10.0.sf.css" type="text/css" rel="stylesheet"/>
<br/>
<div id="innerBody" class="file-box-container">
<div class="errortip" data-bind="text: ErrorMessage, visible: ErrorMessage" style="display: none;"/>
<div class="clear-block">
<div class="upload-button">
<div data-bind="compose: FileList">
<div class="c-content" data-view="_App/Home/Common/FileList/FileList" style="" data-active-view="true">
<div class="secondary-ctrl btnl-row title-noborder clear-block" data-bind="css: { hidden: !ShowSecondary }">
<ul class="context-actions" data-bind="visible: Capabilities.AllowCheckboxes, foreach: CurrentActions">
<li class="hover-list">
<li class="hover-list">
<li class="hover-list">
***<button class="txt context-action" data-bind="click: Click">***
Try this xpath:
//ul[#class='context-actions']/li[3]/button[#class='txt context-action][3]
As per your comments for question, if you want to click on the 3rd button in the list, please try below xpath; I have just tweaked #Saritha's :
(//button[#class='txt context-action'])[3]
This will click on the 3rd button in the page (in the chronological order of DOM representation) with class as txt context-action.
Try this xpath:
//*[#id="innerBody"]/div/div/div/div/div/div/ul/li[3]/button
Related
i am trying to add text in summer note text area but an exception is generated i have tried many method like relative and absolute xpath and class for web element but no one is working
Thread.sleep(3000);
driver.findElement(By.xpath("//div[contains(#class,'note-editable panel-body')]")).sendKeys("test");
/*
driver.findElement(By.xpath(".//*[#id='addTaskFrm']/div[2]/div/div/div/div[3]/div[3]")).sendKeys("test");
*/
/*
driver.findElement(By.xpath("html/body/div[96]/div/div/form/div[2]/div/div/div/div[3]/div[3]")).sendKeys("test");
*/
/*(WebDriverWait wait = new WebDriverWait(driver, 90);// 1 minute
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("note-editable panel-body")));
driver.findElement(By.className("note-editable panel-body")).sendKeys("cancel");*/
HTML code for summer note is
<div class="modal-body">
<div class="row">
<div class="col-xs-12 m-t-md">
<input id="note-title" name="name" value="Cancel Task" type="hidden">
<textarea id="modal-quick-note" class="form-control modal-description-box" name="description" rows="5" placeholder="Description" style="display: none;"></textarea>
<div class="note-editor note-frame panel panel-default">
<div class="note-editing-area">
<div class="note-handle">
<div class="note-control-selection" style="display: none;">
<div class="note-control-selection-bg"></div>
<div class="note-control-holder note-control-nw"></div>
<div class="note-control-holder note-control-ne"></div>
<div class="note-control-holder note-control-sw"></div>
<div class="note-control-sizing note-control-se"></div>
<div class="note-control-selection-info"></div>
</div>
</div>
<textarea class="note-codable"></textarea>
<div style="position: absolute; left: -100000px; opacity: 0;" contenteditable="true"></div>
<div class="note-editable panel-body" style="height: 235px;" contenteditable="true">
<p>
<p>
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: element not visible
Here if I type in something then the list of airports matching that text are shown up!! So is there a general way by which I can select the xpath for it? Here is the screenshot.enter image description here
and here is the HTML:
<document>
<html lang="en">
<head>
<body>
<!-- Keeping body block so that it can be used by public site as well. -->
<nav class="navbar navbar-default navbar-static-top">
<div id="timezone-change-dialog" class="col-md-12 content content-confirmation hidden">
<div class="container-fluid">
<div class="row">
<div class="col-md-12 wizard-steps-container">
<div class="col-md-12 content">
<div class="row">
<div class="col-md-12">
<form id="id_create-shipment-step-2" class="form-horizontal has-validation-callback fv-form fv-form-bootstrap" role="form" method="post" enctype="multipart/form-data" novalidate="novalidate">
<button class="fv-hidden-submit" type="submit" style="display: none; width: 0px; height: 0px;"/>
<input name="csrfmiddlewaretoken" value="gk0wq70Am8U0sKat5IJ6f8nKquxYlZaz" autocomplete="off" type="hidden"/>
<div class="form-group">
<div class="form-group">
<div class="form-group">
<div id="pickup_airport" class="form-group" style="display: block;">
<label class="col-sm-4 control-label" for="">
<div class="col-sm-6 has-success">
<div class="typeahead-container result hint">
<div class="typeahead-field">
<div class="typeahead-result">
<ul class="typeahead-list">
<li class="typeahead-item">
<a href="javascript:;" data-group="airports" data-index="0">
<span>
(
<strong>AIR</strong>
) Aripuana
<strong>Air</strong>
port, Aripuana, MT, BR
</span>
</a>
</li>
<li class="typeahead-item">
<li class="typeahead-item active">
If the span contains text and it is under li tag then you can do that like this.
//span[contains(text(),'airports')]/parent::li
I am not able to run my selenium webdriver tests its not detecting xPath. I tried
driver.findElement(By.xpath(".//*[#id='manageEvents']")).click(); for the
below is HTML code:
<head>
<body style="height: 100%; background-color: aliceblue;">
<div class="container-fluid">
<div class="row">
<!-- Left Side Bar-->
<div class="col-md-3 col-xs-12">
<div class="row">
<div class="row leftMenu">
<div class="row leftMenu">
<div class="row leftMenu">
<div id="manageEvents" class="menuBlk">
<i class="fa fa-folder-open" style="font-size:68px;margin-top:20px" />
<h3 style="margin-top:0px">Manage Events</h3>
</div>
</div>
</div>
<!-- Feed -->
<div class="col-md-6 col-xs-12">
<!-- Right Side Bar -->
<div class="col-md-3 col-xs-12">
</div>
</div>
</body>
</html>
Any help would be appreciated.
Thanks!
You can try to wait until required element appears in DOM and become clickable:
WebElement element = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable(By.xpath(".//*[#id='manageEvents']")));
element.click();
or if your element located inside an iframe, you need to switch to that iframe before searching for element:
driver.switchTo().frame(driver.findElement(By.tagName("iframe")));
driver.findElement(By.xpath(".//*[#id='manageEvents']")).click();
P.S. If there are more than one iframe on page this code might not work, so provide HTML for target iframe to get exact selector for it
Try not to go down to the root of the tree and make
//*[#id="manageEvents"]
I am new to selenium and I have got this problem
This is the code
<document>
<html lang="en">
<head>
<body>
<div id="wrapper">
<nav class="navbar navbar-default navbar-static-top" style="margin-bottom: 0; background-color: #003e7e" role="navigation">
<div id="page-wrapper" style="min-height: 163px;">
<div id="content">
<div id="workArea">
<script type="text/javascript"> $(document).ready(function () { $('.linkdisabled').click(function (e) { e.preventDefault(); }); }); </script>
<div class="simpleForm">
<div>
<div class="row">
<div class="col-lg-12">
<h3 class="page-header">TimeSheet</h3>
<h3>
<span class="link_button btn btn-primary" onclick="location.href= '/TimeSheet/Create'">Click to Add Sheet</span>
</h3>
</div>
</div>
<div class="row show-grid">
</div>
</div>
</div>
</div>
</div>
<div id="footer"/>
</body>
</html>
</document>
================================
And I want to click on this
Click to Add Sheet
Have tired almost all that is there in selenium to identify and click it but it didnt worked... please help
Does it work manually? are you able to click on the text??
Reference -> onclick="location.href='link.html'" does not load page in Safari
I'm using Selenium web driver and trying to click on search image and its unable to click on this. I'm not sure what is going wrong. I have tried
xpath option
driver.findElement(By.xpath("//form/div/div/div/div/div[2]/table/tbody/tr/td[2][#class='icon-button combo-button']")).click();
Also tried for image
driver.findElement(By.xpath("//form/div/div/div/div/div[2]/table/tbody/tr/td[2]/img[contains(#src,'iconActionSearch.png')]")).click();
I have tried exactly the same from Selenium IDE
driver.findElement(By.xpath("//div[#id='divToolbar']/div[2]/table/tbody/tr/td[2]/img")).click();
this is where above code is suppose to act
<td class="icon-button combo-button" title="Search">
<img src="../common/images/iconActionSearch.png">
this is html snippet i have
<!DOCTYPE html>
<html>
<head>
<body class="navigator" onbeforeunload="closeAllChildWindows()" onload="initializeSlideIns()">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<div class="mmenu" style="display: none;">
<form name="navigatorForm">
<div id="pageHeadDiv">
<div class="toolbars">
<div class="toolbar-container">
<div id="divToolbar" class="toolbar-frame">
<div class="toolbar">
<div class="toolbar functions">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="icon-button" nowrap="" itemid="emx567127522162.935" title="Home">
<td class="icon-button combo-button" title="Search">
<img src="../common/images/iconActionSearch.png">
</td>
<td class="menu-arrow" title="Search">
<td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="breadcrumbs">
<script src="./scripts/emxBreadcrumbs.js" type="text/javascript">
<script src="./scripts/emxQuery.js" type="text/javascript">
<script type="text/javascript">
<div id="pageContentDiv" style="top: 62px;">
<div id="layerOverlay" style="display: none;"></div>
<div id="panelSlideIn" class="dialog viewer" style="top: 62px; display: none;">
<div id="windowshadeMask" style="z-index: 50; display: none;">
</form>
<div id="checkoutdiv">
</body>
</html>
try using css selectors alternative:
String cssSelector="td[class='icon-button combo-button']>img"
driver.findElement(By.cssSelector(cssSelector)).click();
a piece of advice: use firebug, firefox extension to verify you located element properly
Just as a different solution to eugene (which, by the way, is a better way of doing it since the CSS selector will be faster), if you must use XPath:
//td[#class='icon-button combo-button']/img
Your original XPath solutions will never work, they are very confined to specific positions. You put in an extra div somewhere and your entire XPath will fall over. So go for something that's a little less brittle.