Dojo: Select element by tag name inside a div selected by ID - dojo

I am looking for an equivalent in Dojo for this jQuery selector
$(">fieldset, #d1") or ("#d1 fieldset")
<div id="d1">
<span>
<fieldset>abc</fieldset>
</span>
</div>
thank you!

The dojo/query module seems to be what you want.
http://dojotoolkit.org/reference-guide/1.9/dojo/query.html

Related

How to replace css class name partially in Vue?

Let's say I have this html element
<div class="progress-bar w-90"></div>
and I want to replace 90 with an object from vue. I tried below but syntax
<div :class="progress-bar w-{{ progress.value }}"></div>
You cannot use {{ }} in attribute/props, better to use template literals as below.
<div :class="`progress-bar w-${progress.value}`"></div>
You can achieve text-binding in this way
<div :class="'progress-bar w-'+progress.value"></div>

Selenium and Xpath - accessing elements adjacent to each other

In the example below I'm trying to click on Follow Me where the adjacent(ish) <div> is equal to David. This is one of many <div class='_1m' on the page all with the same structure.(does that make sense?)
Sorry first time posting a problem and a forgot one major detail. I know that I'm looking for David but I don't know what the 'Follow Me' Value will be. It changes on each record.
<div class="_1m">
<div class="_8h"><img src="/2323.GIF" /></div>
<div class="_1j">
<div class="_1c">David<span class="_13">abc</span></div>
<div>
<span class="_1v">ABCD</span>
<span class="_1v">1234</span>
</div>
<div>7890</div>
</div>
<div class="_3h">
<div class="_n0">
<span class="_bn"><span class="_la">Follow Me</span></span>
</div>
</div>
</div>
To click on Follow Me where the adjacent <div> contains the text David you can use the following Locator Strategy:
Using xpath and following:
//div[contains(., 'David')]//following::span[3]/span
Using xpath, following and the text Follow Me:
//div[contains(., 'David')]//following::span[3]/span[text()='Follow Me']
Use below xpath //div[#class='_1c'][contains(.,'David')]/../following-sibling::div//span[#class='_la'][contains(.,'Follow Me')]
Explaination:
//div[#class='_1c'][contains(.,'David')] loate the David
/.. move to one parent node of David because follow me emement is sibling of that parent div
/following-sibling::div locate immediate following sibling div
//span[#class='_la'][contains(.,'Follow Me')] Loate the span which has Follow me text

Xpath for div with span having a css class get its sibling anchor link

I want all div's anchor link whose span having css class ='block-diff-neutral'
<div class="file-info" xpath="1">
<span class="diffstat tooltipped tooltipped-e" aria-label="0 ">
<span class="block-diff-deleted"></span>
<span class="block-diff-deleted"></span>
<span class="block-diff-neutral" style=""></span>
<span class="block-diff-neutral"></span>
<span class="block-diff-neutral"></span>
</span>
someText
</div>
<div class="file-info" xpath="1">
<span class="diffstat tooltipped tooltipped-e" aria-label="0 ">
<span class="block-diff-deleted"></span>
<span class="block-diff-deleted"></span>
</span>
someText2
</div>
Here div contains 2 subtags i.e. span and a
if span contains a css class as 'block-diff-neutral' only then get the a tag's title attribute => xpath with this condition is required
Expected output is => someText or file1
Your markup looks invalid (it's missing some closing tags) and it looks over convoluted in places (multi-layered <span> tags).
However this should do what you want if I've understood your requirements correctly.
//div[#class="file-info"][./descendant-or-self::span[#class="block-diff-neutral"]]/a
if the span with a missing closing tag is actually a parent of the anchor this would be better:
//div[#class="file-info"][./descendant-or-self::span[#class="block-diff-neutral"]]/descendant-or-self::a
This will find a div with a class of file-info that has a descendent <span> element with the class block-diff-neutral and then find the anchor inside that div element.
To get the title attribute out of the WebElement you would find with this XPath you will need to use .getAttribute("title")
Try the following Xpath.
//span[#class='block-diff-neutral']/parent::span/parent::div/a
Or use following sibling
//span[#class='block-diff-neutral']/parent::span/following-sibling::a
If you are using python use following code and use any of the xpath locator above.
driver.find_element_by_xpath("//span[#class='block-diff-neutral']/parent::span/parent::div/a").text
driver.find_element_by_xpath("//span[#class='block-diff-neutral']/parent::span/parent::div/a").get_attribute("title")
If you are using java try below code and any locator mentioned above.
driver.findElement(By.xpath("//span[#class='block-diff-neutral']/parent::span/following-sibling::a").getText()
driver.findElement(By.xpath("//span[#class='block-diff-neutral']/parent::span/following-sibling::a").getAttribute('title')

How to do AND or OR in XPATH on combined divs

I would like to get a DIV based on two conditions in children DIVs.
//div//[child::div[text()="Administrator"] and //child::div[text='No card']]
But and condition appears to be working on properties of a single element.
Kindly advise how to achieve something like above, using either Xpath or CSSSelector
HTML:
<div>
<div class="src-containers-Quo-SimpleCard-components-styles-index__carHolderRow-" style="transition: s;">
<h4 class="-shared-react-components1Lsp1">Mr.</h4>
<div class="src-containers-Quo-SimpleCard-components-styles-index__carDetails--3xMqU">
<div class="src-containers-Quo-SimpleCard-components-1bGot">bla</div>
<div class="src-containers-Quo-SimpleCard-components--1bGot">Administrator</div>
<div><button class="src-containers-Quo-simpleCard-" type="button">Edit</button><button class="src-containers-Quo-SimpleCard-" type="button">Delete</button></div>
</div>
</div>
</div>
Many thanks
Basically if you want to select div by text values of two child div elements, you can do
//div[div="Administrator" and div="No card"]
Let me know (update your question) if you faced with another issue
P.S. Note that //div[//child::div[text='No card']] means something like return FIRST div if there is a div with text 'No card' somewhere in DOM, but not what you expect

How to check if a web element does not have another inner web element

I am using Selenium and Java to write a test, I need to check if a web element does not have another web element inside it, for example:
<div><span>bla bla</span></div>
<div><g></g></div>
<div><li></li></div>
I need to select the div tags which does not have <span> inside them, so do we have something like:
//div[not(.//span[text()='bla bla'])]
Please do not tell me how to do it in other ways as I already know, I am just wondering if I can do it in a way like the one above.
Your XPath should've done what you wanted. It will select <div> element that doesn't contain, either direct child or nested, span element with text equals "bla bla". See the demo online : http://www.xpathtester.com/xpath/be01362aa9bb1385da6dcf819cf69376
input :
<div>
<div>
<span>bla bla</span>
</div>
<div>
<g/>
</div>
<div>
<li/>
</div>
</div>
output :
<div>
<g/>
</div>
<div>
<li/>
</div>