Click button is not working in protractor - protractor

I am new to angular world. I am in process of automating the angular 2
application but I am having hard time to click a button.
Options tried:
I used various selectors like xpath, CSS, buttonText but none of them is working, s/m throws a timeout message or unable to find a selector.
When I try to print the element in console it is displaying as object object.
Do I need to return the value in format of string and then attempt to click?
Or
Do I need to add any require plug in from NPM ? Please let me know
script snippet:
var resubmit=element.all(by.xpath("//BUTTON[#_ngcontent=''][text()='resubmit']")).get('0');
console.log("return"+resubmit);
resubmit.click();

Wait untill element is become clickable and then click. You do it by following:
EC=protractor.ExpectedConditions;
var resubmit=element.all(by.buttonText('resubmit')).get('0');
browser.wait(EC.elementToBeClickable(resubmit), 15000,'Not Clickable'));
resubmit.click();

Related

Can't click on web element with flutter appium driver that is covered by other element

I tried to test a webview in flutter app using flutter appium driver and faced a problem:
In a webview I have a text, that is placed in two lines. Because of that placing text is covered by another element.
I tried 3 approaches:
1.appium driver: mouse.moveTo then mouse.click.
Solution with mouse.moveTo then mouse.click did not work because appium need other parametr called duration, that is not included to parameters in our appium_driver.
2. Used flutter inspector to locate elements on the webview - solution was not succeed because this webviews are external and were not covered by any flutter overlay.
3. Clicking by bounds
Got all objects from the webview with TESTWorld().appiumDriver.pageSource. Found out that we have the xml with all objects on webview with properties as bounds,text. Made a list with 3 objects of “MyString“ string and clicked on them one by one with click() method from appium_driver. Second element “MyString“ is clickable, appium can click on it, but first instance of this string is in two lines, so this element is part of other big element, that’s why appium_driver can’t click on it.
Maybe someone knows another approach?
Because of that placing text is covered by another element
In a particular case, it sounds like an AUT issue. Appium uses WebDriver API for testing WebView and it is expected to not be able to interact with the overlapped element.
If there is no way to address and fix it in the app, you can try JS to send a click action (the same way we do in Webdriver):
WebElement textElement = driver.findElement(...);
JavascriptExecutor jsEx = (JavascriptExecutor)driver;
jsEx.executeScript("arguments[0].click();", textElement);

One Click vs Two Clicks

Scenario:
Testing web application using Protractor
Element needs to be clicked on to open another page
Designed the test to have one click on the element
Issue:
Sometimes elements needs one click and the test passes but if I run it again the same element needs double clicks
This is causing my test to fails randomly
I verified this by changing the command to have a double click in protractor and it passed.
This is causing inconsistency as I don't know when the element needs one or double clicks.
Any Suggestion is appreciated?
You may just need to put the element into focus explicitly via mouseMove() and then issue a click() action:
browser.actions().mouseMove(elm).click().perform();
Inconsistency might be because of element is not yet ready to click. So you need to wait until element become clickable and click it. Below code will help you in achieving consistency.
Code Snippet:
var EC = protractor.ExpectedConditions;
var elementToBeClick=element(locator);
var timeOut=10000;
browser.wait(EC.elementToBeClickable(elementToBeClick), timeOut).
thenCatch(function () {
assert.fail(' target element is not clickable');
});
elementToBeClick.click();
you can use browser.executeScripts to inject native javascript code into the browser and click the required button. this will execute the click event on the required element that you pass into the function
try the below code,
var elementToBeClick=element(locator);
browser.executeScript("arguments[0].click()",elementToBeClick.getWebElement())

casperjs cant click popup

My code:
casper.waitForSelector('.single_like_button.btn3-wrap .btn3',
function success() {
this.click('.single_like_button.btn3-wrap .btn3');
}
);
Returned:
TypeError: 'undefined' is not an object (evaluating 'window.angular.version')
https://s.ytimg.com/yts/jsbin/www-en_US-vfl2odRpD/angular_base.js:167
https://s.ytimg.com/yts/jsbin/www-en_US-vfl2odRpD/angular_base.js:225
the button when clicked, will open a second tab window, like a popup,
when the second window finished its works, it will close automatically and transfer data back to 1st window.
I dont know if this process had used angular js?
and do i need to install angularjs and how?
beacuse the error seemed related to angularjs
the popup url is inside a javascript's function, i dont know how to scrape it
I dont get the popup url, so i dont know how to use "waitforpopup"
but even if i can get the url, i still have to click the button in order to the correct data transfer. I have used clickLabel("Subscribe", div) , also not working.
Any advices?
I've had issues with waitForSelector before.. Although I'm not familiar with your html/js, why not try the following in place of your code above to do a quick sanity check. This will give you a better idea of what's happening.
this.wait(5000,function(){ // use wait (5 secs) instead of waitForSelector
// log the el to see if it exists at this point
console.log($('.single_like_button.btn3-wrap .btn3').length + " els found");
// click dat
this.click('.single_like_button.btn3-wrap .btn3');
});

TinyMCE get form content without using submit button

I'm trying to put TinyMCE on my website. I figured out how to get it to show up, but I'm lost on how to process the content. In their example, they just have a link that references the top of the page and clicking on it somehow magically causes their dump.php script to execute. I don't understand what's going on here. Here is the link:
http://www.tinymce.com/tryit/basic.php
The "Submit" button at the bottom is really a link in a span element with href="#". The form action is dump.php. I want to know how they configured this to run without an actual submit button. Any help in understanding this is greatly appreciated!
To Get Content From Tinymce You Can Use GetContent Method of Currently ActiveEditor Instance
tinyMCE.activeEditor.getContent();
method is used to getting Content .. to Set The Content
tinyMCE.activeEditor.setContent("I Want Text To Be in Tinymce");
to find a perticular element in tinymce get body and find element
var body = tinyMCE.activeEditor.getBody();
$(body).find("#elem_id")
to get a full html
tinyMCE.activeEditor.getDoc().documentElement.innerHTML
hope that helps ..
Since I use PHP, I found this which is also useful:
http://www.tinymce.com/wiki.php/TinyMCE3x:How-to_implement_TinyMCE_in_PHP

WWW::Selenium to capture component refresh

I am writing a perl script using WWW::Selenium module to automate a website.
I am not at all a web development guy and have no idea about web technologies.
Let me try to explain the issue in layman terms.
I am dealing with a webpage, which has an order form with a button.
When I click the button, there is no page submit, but the button label changes.
Say for eg, the button goes through these changes when clicked multiple times.
Get Quote --> Order --> Confirm Order
Each time I click the button, there is no page refresh, but the button label keeps changing as above.
The id of the button is the same throughout, only the class changes.
How can I do this in WWW::Selenium?
Presently I am using wait_for_page_to_load(5000) after each click.
But the click is not having any effect on the label and I get error that timed out after 5000s.
Should I be using some other function to wait?
You could do something like this
$sel->wait_for_text_present_ok("Your text","time to wait","The message to display if this fails");
and an example below-
$sel->wait_for_text_present_ok("Order Confirmed","9000","The order was successfully placed");
Seems like you could use
$class = $sel->get_attribute($attribute_locator)
where the $attribute_locator is the button#class with button being the element locator that you clicked. Check if $class is the class you expect.