i want to hover on a svg element inside div element with class main. this svg element has title tag "Header element"
below is the code
<div class="main">
<div class="box">
<div class="cell"></div>
<div class="cell"></div>
<div class="cell">
<div>
<svg></svg>
<span> //want to hover on this element
<svg>
<title>Header element</title>
</svg>
</span>
</div>
</div>
</div>
</div>
as seen from code above, i want to hover on span element that contains svg with title Header element.
i have tried using below
cy.get(`.main>div`)
.contains('svg', 'Header element')
.trigger('mouseover')
but this is not working
could someone help me locating this span element using cypress. thanks.
You are selecting the svg but want to hover the span, so add a parent selector
cy.get(`.main>div`)
.contains('svg', 'Header element')
.parent('span')
.trigger('mouseover')
I think you are missing . (class selector)
cy.get(`.main>div`)
.contains('svg', 'Header element')
.triggers('mouseover')
Related
I have multiple divs with multiple imgs under them. I'd like to get the div with the correct img src. How can I do this? I tried this and it didn't work. It just compared the src with the first div and failed.
cy.get('.card').find('.info-section > .logo').should('have.attr', 'src', '/assets/icons/fruit.svg')
Reverse the search order - target the child element with that specific attribute, then traverse to the card parent
cy.get('[src="/assets/icons/fruit.svg"]')
.parent('.card')
It would greatly help your situation if you provided the DOM to see the multiple divs and imgs.
I'll be using the example DOM below.
<div class="card">
<div class="info-section">
<img src="/assets/icons/vegetable.svg" />
<div class="logo">
<img src="/assets/icons/fruit.svg" />
</div>
</div>
</div>
<div class="card">
<div class="info-section">
<img src="/assets/icons/vegetable.svg" />
<div class="logo">
<img src="/assets/icons/fruit.svg" />
</div>
</div>
</div>
To get the <img src="/assets/icons/fruit.svg" /> and test it has src, you will do the following:
cy.get('div.logo') // get div with class logo
.find('img') // find img children
.should('have.length', 1) // should only return 1 element
.should('have.attr', 'src', '/assets/icons/fruit.svg') // should have src attr
I'm trying to select a node whose children do not contain some specific text.
For example:
<div class="b-margin">
<div class="tag">Pt</div>
<div class="tag">En</div>
</div>
<div class="b-margin">
<div class="tag">Ru</div>
<div class="tag">En</div>
</div>
How would i go about selecting the 'div class="b-margin"' nodes that do not have children with the text "Pt"?
Here is the simple xpath.
//div[#class='b-margin' and not(div[.='Pt'])]
Screenshot:
d3.select('.activity:last') and d3.selectAll('.activity:last') both fail. Meanwhile; $('.activity:last') works.
d3.selectAll('.activity:last')
.append('<div class="hook-table">Table comes here</div>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<div class="container">
<div class="activity"></div>
<div class="activity"></div>
<div class="activity"></div>
<div class="activity"></div>
<div class="activity"></div>
</div>
Is there a D3 way to pass :last selector.
:last is not a valid css selector. It works with jQuery because jquery has added support for this selector:
:last is a jQuery extension and not part of the CSS specification (docs)
As D3 only contemplates valid CSS selector strings so :last won't work with D3.
Instead you'll require a bit more code to get the last element.
If your div is the last of of its siblings, then you can use :last-child:
d3.select(".container").select(".activity:last-child")
.text("5: This div selected");
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<div class="container">
<div class="activity"><p>1</p></div>
<div class="activity"><p>2</p></div>
<div class="activity"><p>3</p></div>
<div class="activity"><p>4</p></div>
<div class="activity"><p>5</p></div>
</div>
However, this won't work if you have another element below the last div. The above will select the div with class "activity" that is the last child of .container (see MDN).
For more complex structures, where the last div or element with class "activity" isn't the last sibling, you'll need to take a more complex approach.
I have this html code:
<div class="info">
<div class="label">Phone</div>
<div class="text">+966 (13) 828 3771</div>
</div>
Using XPath, I need to target the Text inside div class text.
For now, I'm using this code and I can target the div class label:
.//*[#class="label"]/text()[contains(.,"Phone")]
How could I target the text inside <div class="text">?
There are other <div class="info"> and <div class="label">, and I need to target those that are direct sibling of <div class="label"> that contains Phone in it.
//div[#class = 'info' and div[#class = 'label' and contains(., 'Phone')]]/div[#class = 'text'] should select the div element(s) with the class attribute text inside a div parent element that has the class attribute info and a child div with class as label and which contains the text Phone.
I have following HTML
<div class='wraper'>
<div class="demo statemachine-demo1">
<div class="w" id="inperson">IN PERSON
<div class="ep"></div>
</div>
<div class="w" id="rejected">
REJECTED
<div class="ep"></div>
</div>
</div>
<div class="demo statemachine-demo1">
<div class="w" id="inperson">IN PERSON
<div class="ep"></div>
</div>
<div class="w" id="rejected">
REJECTED
<div class="ep"></div>
</div>
</div>
</div>as per the above HTML the wrapper div contains two div each .demo div contains two div and are connected to each other .statemachine-demo1 .inperson div to .statemachine-demo2 .inperson(.statemachine-demo1.inperson ----> .statemachine-demo2.inperson) and .statemachine-demo1 .reject to .statemachine-demo2 .reject(.statemachine-demo1.reject -----> .statemachine-demo2.reject).
now if i drag class w the join line will move continuously, but what i want to know is their any way if i drag parent div statemachine-demo1 the child div reject and inperson class div should also move along with joined line continuously.
For this you need customised jquery draggable function instead of using jsPlumb.draggable() for parent div's. Whenever you drag a parent div, you need to check whether any of the child has connection, if so you need to repaint those connections. Code:
$('.demo').draggable({ // considering parent div has 'demo' class as in your case
drag:function(event){
// on drag check any child has connections and repaint them
$(this).find('._jsPlumb_endpoint_anchor_').each(function(i,el){
jsPlumb.repaint($(el));
});
}
});