How to click the buttons without element id - angularjs

Im using protractor for e2e testing.I want to click the buttons

Is there any reason you're not using the Protractor API, but the driver directly? Selecting by ng-click might not be the best approach here as well (good practice seems to be selecting based on page structure, not mechanics), I would recommend you to investigate if you can't simply use by.buttonText:
element(by.buttonText('Place Order'));
EDIT: Looking at the way the selector is made, the above will not work - please note by.buttonText will only match:
button
input type="button"
input type="submit"
I'm keeping this for anyone who might need this in the future.
If that will not work, maybe you could at least select it by class, e.g. inside a parent? For example:
element(by.css('.btn-wrapper > .btn:nth-child(2)'));
Also, consider adding a separate class/id for the button, it might be useful later anyway.
Last remark, if you have a large page to test, consider using page objects instead of selecting same stuff in separate steps. This way, instead of writing the selector, you'll have a nice, maintainable object, that you can use like:
myPage.placeOrderButton().click();
Just something to consider.

Place order button:
$('[ng-if*="checkout"]').click();
Cancel button:
$('[ui-sref=​"main.store.featured"]').click();

This should work:
element(by.css('[ng-click="ctrl.placeOrder()"]')).click();

I think the simplest and the most readable approach here would be to locate the element by text:
element(by.xpath('//div[. = "Place Order"]'));
You may just need to add a wait for element to become visible:
var EC = protractor.ExpectedConditions,
placeOrder = element(by.xpath('//div[. = "Place Order"]'));
browser.wait(EC.visibilityOf(placeOrder), 5000);
placeOrder.click();

I don't know if this will help, but I found an article where someone was having issues clicking on a div. It seems a bit much for just clicking on a div but I figured the link could help you out
https://adventuresintesting.wordpress.com/tag/protractor-doesnt-click-div/

Related

Error stating "element is not found in the cache perhaps the page has changed"

I'm trying to click search button on flipkart through Selenium Webdriver using Java, i'm able to click the button by the X-path and i written 'Boolean' to display button was clicked.
Here's the code:
WebElement search = driver.findElement(By.xpath(".//*[#id='fk-header-search-form']/div/div/div[2]/input[1]"));
search.click();
boolean clicked = search.isEnabled();
System.out.println("Serach Button Clicked"+clicked);
If page is change after click on button, it is normal to not find element. You perform a search peocess, after click, new page being loading.
Another point, isEnabled, everytime returns true except disabled. In this situation, it looks already active.
There are a few issues.
.isEnabled() Determines whether the element is enabled. According to the docs, this is pretty much always going to be true except in a case where there's an INPUT that is disabled (which doesn't apply here). So your code is just telling you that the Search button is not disabled, not whether you clicked it or not.
You didn't post enough code to tell why you are getting this error. I can see what you are trying to do and wrote a simple example of how to do this.
Try this
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.flipkart.com/");
By searchBoxLocator = By.id("fk-top-search-box");
By searchButtonLocator = By.cssSelector("input[value='Search']");
driver.findElement(searchBoxLocator).sendKeys("watch");
driver.findElement(searchButtonLocator).click();
I would suggest that you use something other than XPaths. They are brittle and slower than other methods. In the code above, I used a CSS Selector. Read some tutorials and use this page as a reference. They are very powerful and are, IMHO, better than XPath. There is some stuff that can only be done with XPath... avoid XPath until you hit one of those cases.

Are there any tools for recording web browser events for seleniumn2?

I am looking for something very simple. It can use the Selenium IDE recording tool, but it does not allow me to pick what kind of locators I get.
I want to use:
driver.findElement(By.className(str))
to locate things. All I need is something which watches which UI elements on a web page get clicked and writes out the class attributes of those tags.
If I use the Selenium IDE recording (and export to the right type of thing), I get:
#Test
public void testNav() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.name("3.1.1.5.1.1")).clear();
driver.findElement(By.name("3.1.1.5.1.1")).sendKeys("dan");
driver.findElement(By.name("3.1.1.5.1.5")).click();
driver.findElement(By.linkText("Products")).click();
driver.findElement(By.linkText("Categories")).click();
driver.findElement(By.linkText("Create a Category")).click();
driver.findElement(By.linkText("Cancel")).click();
driver.findElement(By.linkText("Products")).click();
driver.findElement(By.cssSelector("a.DisplayAdminProductsLink")).click();
driver.findElement(By.linkText("Product1")).click();
There are problems with this. First, it is not give me any By.className() calls. Why? Those first 3 calls will not help me. The framework I am using puts arbitrary things into the name. How can I get it to see the class attribute?
There actually are unique words in the class attribute of all of the above tags. I design my apps so that this is so. Yet it will not use them.
Earlier I asked:
Why is it doing a "driver.findElement().click()"? This is fragile and does not
end up working.
What I need is:
elt = driver.waitFor(By.className("c")); elt.click();
This will work reproducibly.....
I am considering to be removed from the question, as the findElement() code does work. You need to set a general time-out on the driver. It is not very obvious that this can be done, but it can.
So, continuing on....
I can go to the "Options" and change the order of the "Locator Builders" in eclipse. I can put "css" at the top. Then I get:
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.1\"]")).clear();
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.1\"]")).sendKeys("dan");
driver.findElement(By.cssSelector("input[name=\"3.1.1.5.1.5\"]")).click();
The tags are like:
<input class="form-control LoginUsernameField" ... />
But it does not see the class attribute.... Or I can do this manually.
Selenium looks for a unique identifier to identify elements in a webpage. classNames are a very less desired option for this purpose as they are generally not unique. Ids and names on the other hand are generally unique. This might be the reason why Selenium IDE is not selecting classNames and going for other identifiers.
Selenium IDE records user actions. You would have clicked on the element for Selenium IDE to identify it and that is why you are getting driver.findElement().click().
If you want to wait for element to wait you can try implicit wait.
When you want to use driver.findElement(By.className(str)), are you sure that there is one and only one element in the webpage that is associated with a className? If that is the case you can modify the webdriver code manually to use className.

Implementing basic next/previous picture

I'm trying to convert the Adjuster example mentioned here: http://agiletoolkit.org/learn/understand/view/interactive
into a View that is able to show me the next/previous picture of a list of given images.
I guess the number in the example could be an index into an array of pictures.
I'm just not sure how to provide the list of pictures, when all the code is put in init() for the View, so no way to give it the picturelist before that...
Should I use memorize/recall for this list also to prevent it getting lost upon reload ?
is there another example that might help me?
I think you what you are doing can be much easier done with a classic JavaScript Lightbox script. You would supply it list of images and it would show one full-screen.
If not, you can use this:
https://gist.github.com/romaninsh/7217119
This will give you slides similar to the ones on http://agiletech.ie/
Be advised that this code is a little old.

How to add a custom field into template.php using Zen sub theme

First time poster here, I'm a designer not skilled at all with php and I have a small issue I don't seem to be able to solve. I'm making a site in drupal 7 using a sub theme on zen.
Btw this is a great CMS, even though people say it's really more a developers CMS. I have no trouble to do what I need using views, rules, display suite etc. So a big thank you for all the developers out there making this such a good CMS. But for this apparently simple problem... no module will help me (I think) and I'm kinda stuck.
So here it is: I'd like to add a subtitle next to the title in all my pages.
So what I did was to add a custom field into the content type basic page (machine name: field_sub_title) which is a simple text field.
I uncommented the following line in my template.php
function mytheme_preprocess_page(&$variables, $hook) {
$variables['sub_title'] = t('field_sub_title');
}
Now my question is how do I load the content of my custom field into that variable?
I know i need to change the second part, but I don't have a clue as into what I need to change this.
Displaying the variable into the the page.tpl.php is something I know about so I only need help with the first part.
{EDIT}
Ok I found how to do this :)
I was looking for a solution in the wrong place. I don't need to change any thing in the template.php file.
Just needed to add this bit of code into my page.tpl.php:
<?php
print $node->field_sub_title['und'][0]['value'];
?>
So I'm posting this here for other Drupal newbies struggling with this....
Your solution may work for now, but there may be a more Drupal-y way to handle a problem like this. If you haven't noticed any problems yet, you may find one or more of the following issues down the road:
Someone who doesn't know php or Drupal theming may need to change the way this works.
If you're like me, you may forget where exactly in code this was implemented.
You may see superfluous markup and/or errors on nodes (content) that do not have this sub-title field (ie. event content not having a sub-title field while basic pages and news articles do).
When you add a field to a content type, it will automatically appear anytime content in that content type is displayed. You should be able to add the sub-title field for your page, event or whatever else you need and have it automatically appear in the markup.
You can 'manage display' of a content type to drag and drop the order for fields to appear. You could take it a step further by using a module like Display Suite to add formatting or layout per-content type.
If you feel like this isn't good enough and the markup for the subtitle must be at the same level as the page title (which is rare), at least add an if statement to make your code check to see if the variable is present before trying to print it. I'd also add a new variable and comments for code readability.
<?php
$subtitle = $node->field_sub_title['und'][0]['value'];
if($subtitle){
print $subtitle;
}
?>
Consider using field_get_items or field_view_value, or at least use the LANGUAGE_NONE constant instead of 'und'
See https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_get_items/7 and https://api.drupal.org/api/drupal/modules!field!field.module/function/field_view_value/7
This has the added benefit of reducing the number of potential security holes you create.

Dojo : FilteringSelect : problems with coming back to valid state

I've came across this issue today and I think I might need some help. We are using 1.6.1 version of Dojo, but this is cross version issue.
Steps to reproduce the following issue are pretty simple:
click the dojo doc link for Filtering Select dijit.form.FilteringSelect
On the documentation page, click the first FilteringSelect sample
In the Codeglass window sample, click the filteringselect and add "x" to "California", thus bringing it to invalid state
While focused, delete the "x" letter.
and here comes the problem. Technically the value is correct, but the dijit is still like in error state (unless it loses focus).
I'd like to get the dijit react and render correctly straightaway I delete the character causing the invalid state without losing focus.
Any ideas for the workaround?
Thank you.
ok. for eveyryone else interested the solution was 'quite' simple, just use the dijit.form.FilteringSelect._refreshState() .The underscore prefix is might not be someone's cup of tea but that was the only way to get it in correct state.
in our case it was a bit tricky as we are using the dojox.data.QueryReadStore wrapped in our own object and I needed the proper trigger which I've found in connecting to onComplete event of the inherited fetch() method.

Resources