Selenium - clicking on button is not recorded - selenium

I am trying to test a web page using Selenium IDE. Am new to selenium.
The code is something like this.
<script src="type="text/javascript">
<script src="max.js" type="text/javascript">
<ul class="toolbar">
<li id="addTitle">
<span class="icon-add">Create New Title</span>
</li>
<li></li>
</ul>
When I click on 'Create New Title' - Selenium does not record anything. Please let me know if I need to provide any further information.
Thanks!
I have tried 'View Xpath'.
But 'View XPath' shows
id('addTitle')/x:span
Results from https://abc.xyz.com/ui/states/LisitTitles.ddx
But I want to add
https://abc.xyz.com/ui/states//ManageStates.ddx?action=add
which is for Create New Title button
I don't see https://abc.xyz.com/ui/states//ManageStates.ddx?action=add
anywhere in the page source code or Xpath.
In Page source I see:
document.location = ABC.PM.TITLE.builderURL + "?action=add";
Also how do I know whether it is Open/Click/etc commands I should be
using? Also does this have something to do with Pagination?
Thanks

You can add this manually by using xPath:
Command | click (or clickAndWait)
Target | //li[#id='addTitle']/span[#class='icon-add']
Value |
It will cause clicking an element containing the text 'Create New Title', as you see.

Open command is for openning a new web page.
Click command is for simulating a user clicking on an element.
On the selenium IDE window you can display all the available commands. You just have to click on the triangle above the "Find" button.
There is also a description for every command in the "Reference" tab
You can take a look on a screenshot here for more informations :
http://seleniumhq.org/docs/02_selenium_ide.html#ide-features#opening-the-ide

Related

Can't click to Customize link when div+link together with FakeAnchor class using selenium web driver

Can't click to Customize link when div+link together with FakeAnchor class using selenium web driver
In my Ajax application, we have dropdown + link (Customize) together in div and i want to click to Customize link. I have locator and which was working fine for Customize link with old selenium but it doesn't with latest web driver. Can anyone please point me the problem or suggest something to make it work?
Expected:
Clicking to Customize link should open respected option (it actually opens dialog).
Actual:
Below locator clicks to dropdown button instead of Customize link due to such a complex page DOM which has no actual href or anchor tag.
Locator:
css=div[id$='_repeatDesc'][class='FakeAnchor']
Html:
<div id="zcs1_repeatDesc" class="FakeAnchor" style="cursor: pointer;">Customize</div>
Code:
webDriver().findElement(By.cssSelector("div[id$='_repeatDesc'][class='FakeAnchor']")).click();
I think your locator is not unique, may be it is locating dropdown element that's why it clicks to dropdown button instead of Customize link.
You should try using By.xpath() with text() node to locate this element as below :-
webDriver().findElement(By.xpath(".//div[text() = 'Customize']")).click();
Or As I'm seeing in HTML element has id attribute, if it's unique I'd to locate desire element and it's not being changed dynamically, you can try also using By.id() as below :-
webDriver().findElement(By.id("zcs1_repeatDesc")).click();
Edited :- If you want to click using JavascriptExecutor try as below :-
((JavascriptExecutor)driver).executeScript("arguments[0].click()", webDriver().findElement(By.xpath(".//div[text() = 'Customize']")));

Behat to click on element by class or ID name?

Is it possible for behat to find an element by class name to click on? It looks like only the following is searched for: id|name|title|alt|value
For example, how could you successfully identify this element to click on?
<a class="button medium round signup" href="http://link.com" data-reveal-id="signupModal">sometext</a>
Also here is a simple page with a button, that has an ID. How come the following does not access the button?
<button id="myBtn" type="button" onclick="myFunction()">Try it</button>
Given I am on "http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_button_form"
When I press "myBtn"
Thanks
The button can not be accessed because it is contained in an iframe, you need to switch to that iframe to make the button available.
You can create steps to click on an element by any type of identifier (class included), or you can implement new step that requires css/xpath selectors.
Here you can find an example of a method to click by selector.
The first HTML code is nothing but a HREF. Behat should be easily able to identify it by using the line below:
Given I follow "sometext"
If the above doesn't work, you can simply use the CSS selector and click the element:
$locator = '.';
$this->getSession()->getPage()->find('css',$locator)->click();

Button needs to have functionality of <a href= and Target=_parent

I have a back button that uses Response.redirect,
This opens up the page I want but in a new window instead of opening it up in the current window(refreshing to new page?)
As <a href= Target=_self would do ? I'm not using this as It need to be a button like the rest of the buttons.
VB.net
Please use j query script reference and use
window.open("foo.aspx");

how to open a link in same page in different content pane using dojo?

I have all anchor tags in left side contentpane of my web page. When i click a link, it will navigates to another another web page. i want that destination web page should open in my center contentpane.
I have hust started DOJO.Please Help me to solve this issue.
Page1
// page1.jsp should open in this section
Note: This example is working only for Dojo 1.8+
Assuming that you have something similar to:
<div data-dojo-type="dijit/layout/ContentPane">
show /link1 in targetPane
show /link2 in targetPane
...
</div>
<div data-dojo-type="dijit/layout/ContentPane" id="targetPane"></div>
The basic instructions follow:
1) Intercept click events on the anchors.
For instance, you can mark the anchors you want to target the content pane with .menuLink class:
show /link1 in targetPane
...then for clicks on those elements:
on(query('.menuLink'), 'click', function(e) {...})
2) Handle the event
Use e.preventDefault(); so that clicking the links won't reload the whole page (as in your current situation :)
Instead instruct the pane to load the link from the anchor:
registry.byId('targetPane').set('href', e.target.getAttribute('href'));
Example
Working example is here (since I've skipped all of the Dojo boilerplate)

Selenium webdriver : Unable to click a link (Not inside iframe- able to print gettext value from the webelement)

Please don't make comments regarding why i posted a similar question. I have tried many things and nothing is working. Below is the HTML
<div id="businessSettingsColumn1">
<div class="sectionLink">
Business details
</div>
<div class="sectionLink">
Operating hours
</div>
<div class="sectionLink">
Closed dates
</div>
<div class="sectionLink">
Appointment notifications
</div>
I need to click the second link
I have tried
1) webdriver.findElement(By.partialLinkText("Operating hours")).click();
2)webDriver.get(mylement.findElement(By.tagName("a")).getAttribute("href"));
3)
List<WebElement> businessLinks= busCol.findElements(By.className("sectionLink"));
for(WebElement bLink :businessLinks) {
if(bLink.getText().contains("Operating hours")) {
bLink.findElement(By.tagName("a")).click();
}
}
4) Using the Action builder to move the mouse and then doing a click
Also when i did this 3 times in a row , my element got clicked
webdriver.findElement(By.partialLinkText("Operating hours")).click();
webdriver.findElement(By.partialLinkText("Operating hours")).click();
webdriver.findElement(By.partialLinkText("Operating hours")).click();
I am using Firefox version 25.0 and Selenium version 2.35.0. Funny thing though is when i do a sysout , the values get printed and when i try to get the url using webdriver I get "Element not found in the cache - perhaps the page has changed since it was looked up" .. its pretty much a static page with links only so i dont understand why i am not able to click it.. Any help will be much appreciated.
Can you try calling focus() on the element before you click on it?
This usually occurs because the element was there at some point, but then something happened and then it's no longer there for some reason. I encounter this frequently when a page makes AJAX calls for example.
Have you tried adding some waits so that selenium is sure that the element is ready?