Selenium assert has class - html

I have an element with a known id. I want to assert or verify that it has a specific class.
The HTML of the element is:
<a id="SearchList" class="something-else disabled"></a>
I want to use the id "SearchList" to locate the element and then verify that it has the class "disabled".
EDITS:
I am using the Selenium IDE a FireFox addon.

verifyElementPresent | css=a[id='SearchList'][class*='disabled'] |

This doesn't help you for the IED, but in C# I can do this using the GetAttribute method.
var allClasses = webElement.GetAttribute("class");
var elementHasClass = allClasses.Split(' ').Any(c => string.Equals("classLookingFor", c, StringComparison.CurrentCultureIgnoreCase));

You could use getAttribute() method to get the attribute and verify that. I assume you use Java for your scripts.
WebElement list = driver.findElement(By.id("SearchList"));
String disabled = list.getAttribute("disabled");
if(disabled.equals("disabled")){
// something
}else{
// something else
}

Sorry for necroposting. I have some addition to what #Purus suggested.
As "disabled" is part of a class name class="something-else disabled", list.getAttribute("disabled") will return null. My suggestion to do it in the following way (Selenium WebDriver Java client):
WebElement element= driver.findElement(By.id("SearchList"));
String elementClass= element.getAttribute("class");
if(elementClass != null && elementClass.contains("disabled")){
// something
}else{
// something else
}

Related

Error with custom Search and Replace function for Google Sites

I'm trying to use a script to replace a particular string with a different string. I think the code is right, but I keep getting the error "Object does not allow properties to be added or changed."
Does anyone know what could be going wrong?
function searchAndReplace() {
var teams = SitesApp.getPageByUrl("https://sites.google.com/a/directory/teams");
var list = teams.getChildren();
list.forEach(function(element){
page = element.getChildren();
});
page.forEach(function(element) {
var html = element.getHtmlContent();
html.replace(/foo/, 'bar');
element.setHtmlContent = html;
});
};
Try This:
Javascript reference:
The replace() method returns a new string with some or all matches of a pattern replaced by a replacement.
I think the issue here is that forEach cannot change the array that it is called upon. From developer.mozilla.org "forEach() does not mutate the array on which it is called (although callback, if invoked, may do so)."
Try doing it with a regular loop.

XAdES-EPES extended to XAdES-T, don't include "xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#" in QualifyingProperties

I have a XAdES-EPES signature, then I extended the signature to XAdES-T using XAdES-4j. The problem is that in the original signature the QualifyingProperties is:
<xades:QualifyingProperties Id="Signature-b8925056-3e5e-4a39-8e4c-7fc1286b5eb5-QualifyingProperties" Target="#Signature-b8925056-3e5e-4a39-8e4c-7fc1286b5eb5-Signature" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#">
And in the extended signature QualifyingProperties is:
<xades:QualifyingProperties Id="Signature-b8925056-3e5e-4a39-8e4c-7fc1286b5eb5-QualifyingProperties" Target="#Signature-b8925056-3e5e-4a39-8e4c-7fc1286b5eb5-Signature" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#">
How can extend the signature without add xmlns:xades141="http://uri.etsi.org/01903/v1.4.1#" to the QualifyingProperties?
Thanks in advance!
Edited: Until I find a solution, I'm doing:
Element qualifyingProperties = null;
final NodeList nlist = xmlSig.getDocument().getElementsByTagName("xades:QualifyingProperties");
if (nlist.getLength() != 0) {
qualifyingProperties = (Element) nlist.item(0);
qualifyingProperties.removeAttribute("xmlns:xades141");
}
The way xades4j is currently doing the XML serialization always adds that namespace declaration, even if there aren't any elements using it. There's no way to configure that. I'd like to only add it when necessary, but that issue hasn't been tackled yet.

MvxTabsFragmentActivity - Remove tabs

Is there any way to remove tabs from an MvxTabsFragmentActivity-inherited class? I mean, currently there's only AddTab<T>() method for adding tabs. But, what if I want to remove tabs?
TIA,
Pap
No - MvxTabsFragmentActivity doesn't provide any RemoveTab functionality currently.
The source for this activity is https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Droid.Fragging/MvxTabsFragmentActivity.cs - you should be able to use this as a starting point for your own needs.
UPDATE:
After following #Stuart's advice and-as I mentioned in my comment below-I added the source code for the MvxTabsFragmentActivity class to my project and added the following method-to remove all tabs-which was all I wanted:
public void RemoveAllTabs()
{
// First, detach the curent tab using SupportFragmentManager object.
if (_currentTab != null)
{
var tag = _currentTab.CachedFragment.Tag;
_currentTab.CachedFragment = SupportFragmentManager.FindFragmentByTag( tag );
if (_currentTab.CachedFragment != null && !_currentTab.CachedFragment.IsDetached)
{
var ft = SupportFragmentManager.BeginTransaction();
ft.Detach( _currentTab.CachedFragment );
ft.Commit();
SupportFragmentManager.ExecutePendingTransactions();
}
}
// Second remove all tabs from TabHost object
if (_tabHost != null)
_tabHost.ClearAllTabs();
// And lastly, empty our _lookup table(actually a Dictionary).
_lookup.Clear();
_currentTab = null; // Clear the current tab
}
I guess if someone wanted to have a specific tab removed he could use the SupportFragmentManager object and have something like this:
public void RemoveTab( string tag )
{
var fragment = SupportFragmentManager.FindFragmentByTag( tag );
if (fragment != null && ! fragment.IsDetached)
{
var ft = SupportFragmentManager.BeginTransaction();
ft.Detach( fragment );
ft.Commit();
SupportFragmentManager.ExecutePendingTransactions();
//_tabHost.TabWidget.RemoveView( fragment.View ); // Neither this..
//_tabHost.RemoveView( fragment.View ); // .. or this removed the tab from the Tabhost.
}
}
However, although the above code was successful at removing the fragment/view inside the tab, the tab itself remained-showing a blank/empty tab. I couldn't find a TabHost.RemoveTab() or TabHost.TabWidget.RemoveTab() methods and the TabHost.RemoveView()/TabHost.TabWidget.RemoveView() did not work.
Notes: I renamed the MvxTabsFragmentActivity to something else and included all copyright notices at the top of the class in my project. Thanks again to #Stuart.

Forced to use template?

This code from Dart worries me:
bool get isTemplate => tagName == 'TEMPLATE' || _isAttributeTemplate;
void _ensureTemplate() {
if (!isTemplate) {
throw new UnsupportedError('$this is not a template.');
}
...
Does this mean that the only way I can modify my document is to make it html5?
What if I want to modify an html4 document and set innerHtml in a div, how do I achieve this?
I am assuming you are asking about the code in dart:html Element?
The method you are referring to is only called by the library itself, and only in methods where isTemplate has to be true, for example this one. If you follow this link, you can also read what other fields/methods work like this.
innerHtml is a field in every subclass of Element which supports it, for example DivElement
Example:
DivElement myDiv1 = new DivElement();
myDiv1.innerHtml = "<p>I am a DIV!</p>";
query("#some_div_id").innerHtml = "<p>Hey, me too!</p>";

CodeMirror textarea.getAttribute is not a function error in mvc3 application

I'm using CodeMirror in my ASP.NET MVC 3 application,
CodeMirror's version is up to date(2.34)
my textarea looks like this:
#Html.TextAreaFieldFor(s => s.Data.CodeBehind, htmlAttributes: new Dictionary<string, object> { { "class", "textbox codeBehind nffp-code" } })
I use CodeMirror like this:
var a = CodeMirror.fromTextArea($code, {
lineNumbers: true,
matchBrackets: true,
mode: "text/x-csharp"
});
where $code is
var $code = jQuery('.nffp-code', $root);
And after page load I have this error:
TypeError: textarea.getAttribute is not a function
codemirror.js
Line 2209
textarea.getAttribute("autofocus") != null && hasFocus == document.body;
I used this manual for using CodeMirror:
manual
Even thought, I'm a total noob in JS, I guess it's hard to do it wrong, still I did.
Any Ideas how to fix the problem?
You need to use document.getElementById() instead of the jQuery lookup.
document.getElementById('contents'); //returns a HTML DOM Object
var contents = $('#contents'); //returns a jQuery Object
In jQuery, to get the same result as document.getElementById(), you can access the jQuery Object and get the first element in the object (Remember JavaScript objects act similar to associative arrays).
var contents = $('#contents')[0]; //returns a HTML DOM Object