how do I validate a particular script in persent in page source using selenium? - selenium

In page source I have script tags as below,
how to validate in selenium that particular scripts are persent???
<script src="/core/assets/vendor/domready/ready.min.js?v=1.0.8"></script>
<script src="/core/misc/drupalSettingsLoader.js?v=8.4.8"></script>
<script src="/core/misc/drupal.js?v=8.4.8"></script>
<script src="/core/misc/drupal.init.js?v=8.4.8"></script>

you can search for attribute src within a script. i.e. finding element by attribute
driver.findElement(By.xpath("//script[#src='/core/assets/vendor/domready/ready.min.js?v=1.0.8']"))
OR
driver.findElement(By.xpath("//script[contains(#src,'/core/assets/vendor/domready/ready.min.js?v=1.0.8')]")
OR
driver.findElement(By.cssSelector("script[src='/core/assets/vendor/domready/ready.min.js?v=1.0.8']"))

Related

Protractor Conditional Selector

I am using Selenium Protractor and want to select all elements from the following list except one that contains text "Cat" and then perform some operations on the remaining ones.
<div class="mainDiv">
<div class="childDiv">Dog</div>
<div class="childDiv">Goat</div>
<div class="childDiv">Bird</div>
<div class="childDiv">Cat</div>
<div class="childDiv">Zebra</div>
</div>
Is there a selector by cssContainingText (or some other) in which I can give a condition to select all elements except the one containing text "Cat"?
You can create a List selecting all the elements except one that contains text Cat using the following Locator Strategy:
xpath:
//div[#class='mainDiv']//div[#class='childDiv'][not(contains(.,'Cat'))]
When using Selenium and css-selectors:
The :contains pseudo-class isn't in the CSS Spec and is not supported by either Firefox or Chrome (even outside WebDriver). You can find a detailed discussion in selenium.common.exceptions.InvalidSelectorException with “span:contains('string')”
However, if the elements always appears within the DOM Tree in a specific order, e.g. Cat always at the forth child, you can also use:
cssSelector:
div.mainDiv div.childDiv:not(:nth-child(4))
Reference
You can find a couple of relevant discussions in:
While fetching all links,Ignore logout link from the loop and continue navigation in selenium java
How to write a CSS Selector selecting elements NOT having a certain attribute?

Where do I find the "the HTMLQuestion schema URL" and CDATA (newbie ... run out of options)

I want to conduct a simple turk survey.
I've made the form, uploaded the images and set the details but I'm not quite sure what's next.
Here is the framework of my form with what I think are the AWS elements needed but:
1) How do I find the "the HTMLQuestion schema URL"?
2) Do I generate the assignmentId or does it get inserted on the POST?
3) Is there something I need to add for CDATA is it is a placeholder for an array?
(Please forgive my ignorance but I may even being asking the wrong questions. I'm just not clear what to do next - especially to test it myself (sandbox). I tried posting in the Turk forum but no replies in two days. I don't expect the AWS manual to be for novices.)
<pre>
<HTMLQuestion xmlns="[the HTMLQuestion schema URL]">
<HTMLContent><![CDATA[
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
<script type='text/javascript' src='https://s3.amazonaws.com/mturk-public/externalHIT_v1.js'></script>
</head>
<body>
<form name='mturk_form' method='post' id='mturk_form' action='https://www.mturk.com/mturk/externalSubmit'>
<input type='hidden' value='' name='assignmentId' id='assignmentId'/>
... my handwritten form elements ...
</form>
<script language='Javascript'>turkSetAssignmentID();</script>
</body>
</html>
]]>
</HTMLContent>
<FrameHeight>0</FrameHeight>
</HTMLQuestion>
</pre>
Here is the latest link I found so far:
<HTMLQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2011-11-11/HTMLQuestion.xsd">

MSBuild to update html tag

Here is my html file:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script id="ScriptId" src=""></script>
</body>
</html>
I want to replace empty src by script.js.
I tried with XmlPoke, but my XPath query doesn't work I think or maybe I can't do this way:
<XmlPoke XmlInputPath="test.html"
Query="/html/body/script[id='ScriptId']/src"
Value="script.js"/>
Thanks in advance to help me to update this src value.
Attributes in XPath are prefixed with #.
/html/body/script[#id='ScriptId']/#src
You probably shouldn't be using something designed for XML with HTML as two are not the same, at best, if HTML is well-formed, it'll strip out non-XML stuff like DOCTYPE, at worst it'll blow up.

VBA insertAdjacentHTML , stripping tags

I am processing some HTML in VBA and want to inject a element to the tag.
oElement.insertAdjacentHTML "beforeEnd", "<base>HELLO</base>"
If I inspect the oElement.OuterHTML all that is added is HELLO
...<LINK rel=stylesheet type=text/css href="css/default.css">HELLO</HEAD>...
If I try adding li tags , it works as expected.
oElement.insertAdjacentHTML "beforeEnd", "<li>HELLO</li>"
Result
....<LINK rel=stylesheet type=text/css href="css/default.css">HELLO <LI>HELLO</LI> </HEAD>...
I've tried using just <base /> or <base href="blah blah , nothing get's added. Am I missing some key piece of knowledge about insertAdjacentHTML.
Any ideas??
You need to use IHTMLDOMNode interface for head object (don't know why, but it works). Create a "BASE" element, set attribute for href and finally add it to a head using appendChild.

libxml2 get inner (X)HTML

I have some sample XHTML data, like this:
<html>
<head>
<style type="text/css">
..snip
</style>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0a4.1/jquery.mobile-1.0a4.1.js"></script>
</head>
<body>
<div id="contentA">
This is sample content <b> that is bolded as well </b>
</div>
</body>
</html>
Now, what I need to do, is using an xmlNode *, get the inner HTML of the div contentA. I have the xmlNode * for it, but how can I get the innerXML of that? I looked at content, but that only returns This is sample content and not the xml in the bold tags. I looked into jQuery for this, but due to limitations on Apple and JavaScript, I cannot use jQuery to get the innerXML of that node.
On another note, Is there another library I should be using to get the inner XML? I looked into TBXML, but that had the same problem.
The content of the div node is not a single text string. It probably consists of:
A text node containing This is sample content (with the preceding new line).
an element node with a tag name of b
A text node containing the trailing new line and the indentation up to the div's closing tag.
The element node for the <b>...</b> will have the text content that is bolded as well.
To get all the text in the div as one string, you'll need to recursively descend through the entire tree of child nodes looking for text content.