Selenium: unable to click on class and image - testing

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.

Related

Selenium:- Popup handelling in HTML

I am using Firefox Quantum.
It's something different than Mozzila firefox. I can't use firebug now as it is not supporting.How can i verify that the i am on a different frame.
As currently i can't write on the popup message. Maybe it is on different frame.
Can anyone explain me with proper example.
The HTMLM of the code is:-
<div class="store_form">
<div class="row">
<div class="col s12 m12 marg-top">
<div class="row">
<div class="col s12 m6 store_band_contact">
</div>
<div class="col s12 m6 store_add_left">
</div>
</div>
</div>
<form id="form_contact" class="col s12 m12" novalidate="novalidate">
<div id="errorMsg"></div>
<!-- <div class="row">
<p class="col s12" style="font-size: 15px;" >
<strong id="buyer_company"></strong>
</p>
</div> -->
<!-- <div class="row">
<p class="col s12" id="">Subject: Request to remove my bid
</p>
</div> -->
<div class="row">
<div class="input-field col s12">
<span class="editFiledHeading">Request to remove my bid</span>
<!-- Contact Seller -->
<textarea name="comment" maxlength="20000" id="comment" class="ckeditor" placeholder="" style="visibility: hidden; display: none;"></textarea><div id="cke_comment" class="cke_1 cke cke_reset cke_chrome cke_editor_comment cke_ltr cke_browser_webkit" dir="ltr" lang="en" role="application" aria-labelledby="cke_comment_arialbl" style="width: 99.8%;"><span id="cke_comment_arialbl" class="cke_voice_label">Rich Text Editor, comment</span><div class="cke_inner cke_reset" role="presentation"><span id="cke_1_top" class="cke_top cke_reset_all" role="presentation" style="height: auto; user-select: none;"><span id="cke_12" class="cke_voice_label">Editor toolbars</span><span id="cke_1_toolbox" class="cke_toolbox" role="group" aria-labelledby="cke_12" onmousedown="return false;"></span></span><div id="cke_1_contents" class="cke_contents cke_reset" role="presentation" style="height: 200px;"><span id="cke_16" class="cke_voice_label">Press ALT 0 for help</span><iframe src="" frameborder="0" class="cke_wysiwyg_frame cke_reset" title="Rich Text Editor, comment" aria-describedby="cke_16" tabindex="0" allowtransparency="true" style="width: 439px; height: 100%;"></iframe></div></div></div>
<input type="hidden" name="bid" id="bid_id" value="1035">
</div>
</div>
<div class="row" style="margin-top: 10px;">
<div class="col s6">
<p style="margin: 5px 0 0;">
<input type="checkbox" name="is_copy" id="is_copy" value="1">
<label for="is_copy">Send me a copy</label>
</p>
</div>
<div class="col s6">
<span class="right remainingLimit" id="comment_label" data-length="2500">Remaining: 2500</span>
</div>
</div>
<div class="row">
<div class="col s12">
<p class="defaultP">
If you like to remove a bid you can do that by
sending the request to the seller. Please make
sure that you state the reason for doing this.
Obvious accidents by using the wrong value are
easy to justify.
Please note that it is up to the seller to accept
or decline your request!
</p>
</div>
</div>
<div class="row">
<div class="col s12 center" style="margin: 20px 0 15px;">
<button class="transParentBtnSmall">Submit</button>
</div>
</div>
</form>
</div>
</div>

ElementNotVisibleException: element not visible in web driver

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

I want to select xpath of the following dropdown list of Airports

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

Unable to locate an element in selenium webdriver using name and xpath

Am very new to Selenium just learnt few things and trying to automate.Unable to locate an element in Selenium webdriver for the below one:
<tbody class="jira-restfultable-create">
<tr class="jira-restfultable-row jira-restfultable-editrow jira restfultable-focused">
<td class="jira-restfultable-order">
<td></td>
<td><textarea class="ztextarea noresize ztextarea-step" rows="4" name="step"> </textarea>
</td>
<td>
I have written code like
driver.findElement(By.name("step")).sendKeys("step-1");
and also tried with
driver.findElement(By.xpath("//*[#name = 'ztextarea noresize ztextarea-step']")).sendKeys("step-1");
Anyone please help me.
And also please suggest some sites or links to learn more about locators especially xpath. I tried few but not getting it in depth.
Thanks in advance.
<!DOCTYPE html>
<html class="mozilla">
<head>
<body id="jira" class="aui-layout aui-theme-default ka ajax-issue-search-and-view page-type-navigator navigator-issue-only" data-version="6.2" data-aui-version="5.3.5">
<div id="page">
<header id="header" role="banner">
<fieldset class="parameters hidden dont-default-focus">
<script type="text/javascript">
<nav class="aui-header aui-dropdown2-trigger-group" role="navigation" data-aui-responsive="true">
<div class="aui-header-inner">
<div class="aui-header-primary">
<h1 id="logo" class="aui-header-logo aui-header-logo-custom">
<ul class="aui-nav" style="width: auto;">
<li>
<li>
<li>
<li>
<li>
<a id="zephyr_je.topnav.tests" class="aui-nav-link aui-dropdown2-trigger " aria-owns="zephyr_je.topnav.tests-content" aria-haspopup="true" title="Zephyr Test Management and Execution" href="/secure/ZephyrWelcome.jspa">Tests</a>
<div id="zephyr_je.topnav.tests-content" class="aui-dropdown2 aui-style-default">
</li>
<li style="display: none;">
<li id="create-menu">
</ul>
</div>
<div class="aui-header-secondary">
</div>
</nav>
</header>
<section id="content" role="main">
<div class="issue-container" tabindex="-1">
<div id="issue-content" class="issue-edit-form">
<div class="stalker-placeholder issue-header js-stalker" style="visibility: hidden; height: 135px; width: 1349px;"></div>
<header id="stalker" class="issue-header js-stalker detached" style="position: fixed; top: 0px; left: 0px;">
<div class="issue-body-content">
<div class="aui-group issue-body">
<div class="aui-item issue-main-column">
<div id="details-module" class="module toggle-wrap">
<div id="descriptionmodule" class="module toggle-wrap">
<div id="view_issue_steps_section" class="module toggle-wrap">
<div id="view_issue_steps_section_heading" class="mod-header">
<div class="mod-content">
<div id="project-config-panel-versions" class="project-config-panel">
<form id="project-config-versions-add" class="aui" action="#">
<table id="project-config-steps-table" class="aui jira-restfultable jira-restfultable-allowhover">
<thead>
<tbody class="ui-sortable">
<tbody class="jira-restfultable-create">
<tr class="jira-restfultable-row jira-restfultable-editrow jira-restfultable-focused">
<td class="jira-restfultable-order">
<td></td>
<td style="height: 81px;">
<textarea class="ztextarea noresize ztextarea-step" rows="4" name="step" style="height: 72px;"></textarea>
</td>
<td style="height: 81px;">
<td style="height: 81px;">
<td class="jira-restfultable-operations">
<div class="restfultable-operations-wrapper">
<input class="aui-button" type="submit" value="Add" accesskey="s">
</div>
</td>
<td class="jira-restfultable-throbber"></td>
</tr>
</tbody>
</table>
</form>
<div id="project-config-error-console"></div>
</div>
</div>
</div>
<div id="view_issue_execution_section" class="module toggle-wrap">
<div id="view_issue_execution_section_heading" class="mod-header">
<div class="mod-content">
</div>
<div id="activitymodule" class="module toggle-wrap">
<div id="addcomment" class="module">
<div class="mod-content">
<div class="mod-footer">
</div>
</div>
<div id="viewissuesidebar" class="aui-item issue-side-column">
</div>
</div>
</div>
</div>
<fieldset class="hidden parameters">
<div id="systemFiltersJson" style="display:none;">[{"id":-1,"name":"My Open Issues","jql":"assignee = currentUser() AND resolution = Unresolved ORDER BY updatedDate DESC","isSystem":true,"sharePermissions":[],"requiresLogin":true},{"id":-2,"name":"Reported by Me","jql":"reporter = currentUser() ORDER BY createdDate DESC","isSystem":true,"sharePermissions":[],"requiresLogin":true},{"id":-3,"name":"Recently Viewed","jql":"issuekey in issueHistory() ORDER BY lastViewed DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false},{"id":-4,"name":"All Issues","jql":"ORDER BY createdDate DESC","isSystem":true,"sharePermissions":[],"requiresLogin":false}]</div>
<div id="inline-dialog-c14577633211060" class="aui-inline-dialog aui-help-tip" style="top: 116px; right: 10px; display: none;">
</section>
<footer id="footer" role="contentinfo">
</div>
<div id="fancybox-tmp"></div>
<div id="fancybox-loading">
<div id="fancybox-overlay"></div>
<div id="fancybox-wrap">
<div id="edit-issue-dialog" class="jira-dialog box-shadow" style="display: none;">
<div id="create-subtask-dialog" class="jira-dialog box-shadow" style="display: none;">
</body>
</html>
try following code.
//Get by Name
driver.findElement(By.name("step")).sendKeys("step-1");
// Get by Tag Name
driver.findElement(By.tagName("textarea")).sendKeys("step-1");
//Get element using css selector
WebElement textArea= driver.findElement(By.cssSelector("textarea[name='step']"));

Selenium web driver: unable to locate element

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