Select a hidden element with PHPunit - selenium

Is it possible to locate an element altho it is hidden? I want a function that looks for my tooltip that says something was not filled correctly in my form.
the function looks like this:
public function checkTooltip()
{
$element = $this->byClassName('tooltip');
if ($element->displayed())
{
echo "something was not filled correctly";
}
}
$var1->value('hello');
$this->checkTooltip();
$var2->value('world');
$this->checkTooltip();
$var3->value('!');
$this->checkTooltip();
This works perfectly when the tooltip appears but if there is nothing wrong I get the message:
"PHPUnit_Extensions_Selenium2TestCase_WebDriverException: no such element"
And this make sence because it's hidden when nothing is going wrong but I want to select that element anyways, becouse I want my test to make sure that it's not vissible during my test to make sure everything is okey.So is there a way to select a hidden element using phpunit_Selenium2TestCase?

This worked as a charm!
public function checkError()
{
$tooltip = $this->elements($this->using('css selector')->value('div.active div.invalid'));
if(count($tooltip) != 0)
{
foreach ($tooltip as $tool)
{
$warning = $tool->text();
echo "You got a invalid tooltip with this message '".$warning."'";
}
}
}

Related

Webdriver.io browser.getText() sometimes returns undefined

I have this piece of code:
getText: (selector) => {
browser.waitUntil(function () {
return browser.isExisting(selector) === true;
},timeout,
'Could not find element after: ' + timeout,
pollingTime);
return browser.getText(selector);
}
And sometimes this function (getText(selector), but in deep browser.getText(selector)) returns undefined for the selector that looks like this:
article[data-product-id="test-00020"] li.product-entry__summary__item.is-price span
This doesn't happen every time test is run, but it happens occasionally. It is driving me nuts because the behavior is inconsistent. Sometimes it works and sometimes it doesn't.
Did anybody have similar problems? Please help! Thank you.
getText is dependent on the element being visible in the viewport of the page (so if it's scrolled off the page it will return an empty string)
Instead, you can use getHTML(false) to get the text content of an element (just ensure it's the inner-most element, otherwise you'll get HTML elements in the returned content)
If you use getHTML which I also did, you can strip out the HTML tags if they are not innerHTML:
var strArray = browser.getHTML("//div[myxpath]");
for(var i =0; i<strArray.length; i++){
strArray[i]=strArray[i].replace(/(<([^>]+)>)/ig, "");
strArray[i] = strArray[i].trim();
}
sorry for the Hungarian notation.

errorhandler layout in yii not rendering

searched around. The layouts doesn't render.
Things I've tried:
changed the layout path. Doesn't render.
create init, Yii::app()->errorHandler->errorAction='site/error'; and changed to
something like errorAction='hi'. Which did respond to say can't
find hi.
Went to site/error file and typed hi in view,.. it never says hi to me :(
created protected/views/system and changed the error files. Nothing.
Also followed the first answer on this page
main config is 'errorAction'=>'site/error',
public function actionError()
{
$this->layout = 'main'; //also tried '//layouts/main'
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
else
throw new CHttpException(404, 'Page not found.');
}

toggle (hide/show) in Extjs4

I am trying to do something like : when user click on the button, the child panel will show/hide
the issue is the 'onbtnClick' function is working just once. when i click on the button the panel shows and then when i click it again nothing happens and no errors tho ! the panel should hide
By the looks of it, there isn't really much need to pass a boolean param to the function.
If you purely want a 'toggle' function, based on the panels visibility and you have a reference to the Ext component, you can use the isVisible() function:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.panel.Panel-method-isVisible
So your onBtnClick function would look something like this:
onbtnClick: function (){
var childPanel = Ext.getCmp('p');
if(childPanel.isVisible()) {
childPanel.hide();
}
else {
childPanel.show();
}
}
onbtnClick: function (){
var childPanel = Ext.getCmp('p');
if (!childPanel.isHidden()) {
childPanel.hide();
} else {
childPanel.show();
}
}
Instead isVisible() use method isHidden() because method isVisible may return false when the panel is covered by other components or is not rendered yet (even when your panel has not got hidden property (hidden = false)).
panel.getEl().toggle();
will serve your purpose.
-YP
you have setVisible, taking a boolean parameter to know what to do.
childPanel.setVisible( ! childPanel.isVisible() )
This example will actually toggle the visibility at each execution.

Confirm Message on DropDown Select Change

I need to show a Confirm message when the value Hiring is selected in the dropdown. How can I do that?
if (Status.SelectedValue == "HIRING")
{
Status.Attributes.Add("onChange", "javascript:return DisplayConfirmation();");
}
I have the function DisplayConfirmation in aspx page. This does not work.
Alter the DisplayConfirmation() javascript function to include a parameter for the selected value, and handle the logic inside the function.
In the Code behind, replace your code with this:
Status.Attributes.Add("OnChange", string.Format("DisplayConfirmation('{0}');", Status.SelectedValue));
So, you can change your javascript to be
function DisplayConfirmation(Status) {
if(Status == "HIRING")
{
if (confirm('Are you sure you want to do this?')) { __doPostback('Status', ''); }
}}

dojo TimeTextBox don't listen to on blur event

I want to add an on blur event to a dojo timetextbox but the event never been runned
so the declaration of the timetextbox is like this:
<label>End</label><input id="endp" name="endp" onBlur="calculateTimeSpent2(startp,endp,output);" />
the javascript function is like this:
function calculateTimeSpent2(startp,endp,outputp)
{
var tmp0=document.getElementById('startp').value.split(':');
var tmp1=document.getElementById('endp').value.split(':');
if (tmp0[0]!='' && tmp1[0]!='')
{
var val1= findtime(tmp0[0],tmp0[1],tmp1[0],tmp1[1]);
var tmp=val1.split(':');
if (tmp[0].indexOf('-')==-1)
document.getElementById('outputp').value=val1;
else
{
alert ("Start Time must be lower than End Time ");
document.getElementById('endp').focus();
}
}
}
I don't understand why dojo didn't execute the event correctly while loosing the focus.
I tried to put the type=text but it does'nt work.
Thanks for help.
startp, endp and output are probably undefined at the time the method handler is invoked. It doesn't look like your function actually uses the arguments it names. Perhaps you don't need to pass in any values at all?