I have a (I hope) simple question. Is there a way to change something like
<div id='THE_ID' class='filter_group'> subtags </div>
to
<div id='THE_ID' class='filter_group open'> subtags </div> in capybara?
This website I'm looking at has a non-descript <a> tag as a button that edits the div class as seen above.
I'd rather click the <a> tag but it being non-descript has no information. No name, no id, no href, nothing.
I'm new to rails and capybara so please forgive me if I'm missing something simple
The code block I am looking at is
<div id="ctl00_ContentPlaceHolder1_as1_divDateRange" class="filter_group">
<label class="header">Date Range
<span class="label two-line"><span id="ctl00_ContentPlaceHolder1_as1_lblDateFrom">4/14/2018</span><br><span id="ctl00_ContentPlaceHolder1_as1_lblDateTo">6/14/2018</span></span>
<a></a>
</label>
<div class="list">
RADIOBUTTONS and FIELDS
</div>
</div>
What you're asking is possible using JS, however then you're not really testing the site (assuming you're testing and not just scraping). To do it via JS with Capybara 3.2+ you could do
page.find("#ctl00_ContentPlaceHolder1_as1_divDateRange").execute_script("this.classList.add('open');")
Prior to 3.2 you would need to do something like
el = page.find("#ctl00_ContentPlaceHolder1_as1_divDateRange")
page.execute_script("arguments[0].classList.add('open');", el)
That being said, there are plenty of ways to click the <a> even if it doesn't have any usable attributes (assuming it has size on the page) by scoping to it
page.find("#ctl00_ContentPlaceHolder1_as1_divDateRange > .header > a").click
Here is some code (Sorry it's pure javascript I didn't see the part of your question where it says it's ment to be with cappybra):
function yourFunction() {
var element = document.getElementById("ctl00_ContentPlaceHolder1_as1_divDateRange");
element.classList.add("open");
}
.open {
color:red;
}
<button onclick="yourFunction()">Add class</button>
<div id="ctl00_ContentPlaceHolder1_as1_divDateRange" class="filter_group">
<label class="header">Date Range
<span class="label two-line"><span id="ctl00_ContentPlaceHolder1_as1_lblDateFrom">4/14/2018</span><br><span id="ctl00_ContentPlaceHolder1_as1_lblDateTo">6/14/2018</span></span>
<a></a>
</label>
<div class="list">
RADIOBUTTONS and FIELDS
</div>
</div>
The CSS part is to demonstrate that the class has beeen added.
Hope I helped you and others :)
Related
I want to show/hide a specific div on-click, but there are some serious caveats. I should also mention I fundamentally know how to do this, using answers gleaned from similar questions here (eg., http://jsfiddle.net/6W7XD/1/), but this is more for the specific situation.
I have a CMS which will not allow me to edit the HTML at all outside of specific modules. Additionally, the CMS is one of those which disables id selectors, so I cannot use those, either.
I understand that the JSFiddle example I provided hinges on specific sibling/child selectors, but I'm wondering if there's a selector which would work for this situation. I can only edit the html in the first module (for simplicity's sake, I'll call it .module-1), but I want to show/hide .module-4
The arrangement of the code in the CMS, however, is a little bit byzantine.
This is a parred down version of what I'm working with (this is for a sidebar, by the way, housed under the beta id). I cannot edit any of the fundamental structure, except in the place marked:
<div id="beta-inner" class="pkg">
<div class="module-1 module">
<div class="module-inner">
<div class="module-content">
<!-- I can edit this area only, so this is where I would place my show/hide link. If the jsfiddle method I posted is appropriate in this situation, I'm assuming it would show/hide after clicking on links placed here. -->
<span class="span3" tabindex="0">Hide Module-4</span>
<span class="span2" tabindex="0">Show Module-4</span>
</div>
</div>
</div>
<div class="module-4 module">
<!-- this is the module I want to show/hide -->
<div class="module-inner">
<div class="module-content">
</div>
</div>
</div>
</div>
</div>
I can edit the CSS as much as I want, provided I don't use id (which has been made inaccessible to prevent people messing up the CMS? I think that's the rationale offered), and I believe that precludes the checkbox hack entirely.
I cannot use JQuery/JS/anything of that nature, since they're disabled. I know this would be a quick thing with jquery, but unfortunately, there's nothing I can do about that.
So... if this is possible... how would I go about doing it?
I'm using an app that allow me to change only the CSS of a webpage.
The devs create a step_btn class for 2 distinct buttons (previous and next button) and i want to change the CSS of each button separately.
I tried to make the changes through the div id but nothing happened...
Here is the page code :
<div id="j_id0:j_id73" class="navbuttonsContainer">
<div id="j_id0:j_id74" style="height:35px;overflow:visible;position:relative;" class="rowElem">
<div id="j_id0:j_id78" class="btnWrapper">
<a class="step_btn" onclick="saveAndGoTo('next')" title="Next Page">
<span id="j_id0:nextBtn">Next Page</span>
</a>
</div>
<div id="j_id0:j_id81"></div>
</div>
</div>
Here are my tries :
#j_id0:j_id78
div#j_id0:j_id78 {}
div#j_id0:j_id78 .step_btn {}
Is it my tries that failed or the webpage doesn't interpret my code correctly ?
Thanks for your help !
use an attribute selector to enclose the id as a string, e.g.
[id="j_id0:j_id78"] .step_btn { ... }
In fact using the id selector — like for #j_id0:j_id78 — the parser would consider j_id0 as the id and :j_id78 as a pseudoselector
Note: no need to specify the div element in front of the attribute, since the id should be unique in the page.
On my webpage there are DIV's that are created dynamically with the class of jOUT.
I want to change the color of every other iteration of the class.
I'm trying to do it this way:
.jOUT:nth-child(even){
background:#eeefff;
}
.jOUT:nth-child(odd){
background:#cccffe;
}
My HTML is as follows:
<div id="outData">
<input type="hidden" name="outDivider" value="-------">
<div class="jOUT isOpaque">
<!-- ... -->
</div>
<input type="hidden" name="outDivider" value="-------">
<div class="jOUT isOpaque">
<!-- ... -->
</div>
<input type="hidden" name="outDivider" value="-------">
<div class="jOUT">
<!-- ... -->
</div>
</div>
Full HTML here
But it's not working. What's really weird is that using the console in Chrome, when I select each jOUT, it shows ALL of them as having the "even" attribute.
I thought for sure that I had invalid CSS or HTML but I can't find it. It has to be something I'm doing, but what? I guess what I'm asking for is an idea for a place to start looking for the problem. I've verified the CSS using w3c CSS verification, and the HTML using HTML Tidy.
Your current CSS is working as it should, because you're targeting ALL children (including input); which means, in this scenario, all your div.jOUT are even - you should rather use :nth-of-type, which will only target instances of div.jOUT ...
.jOUT:nth-of-type(even){
background:#eeefff;
}
.jOUT:nth-of-type(odd){
background:#cccffe;
}
DEMO fiddle
This would work here:
.jOUT:nth-child(4n){
background:#eeefff;
}
More on that
This is somewhat fragile, though. A better approach is to add an alternative style class on those elements, possibly via your server-side app.
Your input[name="outDivider"] elements are in the way, thus making every jOUT element even. Here's a working pen where I took them out and made the selector work properly. I also changed the colors, so it's easier to see.
Edit: #isherwood beat me to it, but if this input[name="outDivider"] elements are absolutely necessary, his solution works best!
I have been created simple web page using html, css and some scripts.
Here is my jsfiddle i tried: http://jsfiddle.net/67x8cyp9/
<p>
<img class="text-wrap" align="right" src="img/9780143332497.jpg">
<div class="caption">
<form method="get" action="9780143332497.png">
<button type="submit">Download!</button>
</form>
</div>
</p>
Is it correct to use <form> tag and <div> tag inside <p> tag?
And also, how to set download button under the image?
Can anyone help me to fix this?
Thanks in advance.
Its NOT recommended.
According to W3 specifications, <p> is only allowed to contain text or 'inline' (not 'block') tags. However a <form> counts as 'block' content not as 'inline' content(see this for Minimal Content Model in <p> tag). Alternately, you may use a <div> to enclose your <form>
You may validate your html code on w3 validator for better clarity.
Cheers!
Not it is not, p is a block element, but cannot contain other block elements, only inline ones. (at least in HTML4, but I don't think HTML5 changes this behaviour).
Hmm, according to MDN, you can put a form in a p, but actually what happens is that the end of the p is at the beginning of the form, so not very useful.
Update:
To help you in your current actual problem, you can wrap the content in a div instead of a p:
<div class="right-figure">
<img class="text-wrap" src="img/9780143332497.jpg">
<div class="caption">
<form method="get" action="9780143332497.png">
<button type="submit">Download!</button>
</form>
</div>
</div>
And in the CSS file:
.right-figure {
float: right;
}
This will do, what you need.
Another approach:
By the way, you could also just use a link instead of a form:
Download!
and format the anchor with CSS to look like a button, just like e.g. Twitter Bootstrap does.
I got this html
<div contenteditable="true"> Hey <a class="tgt" contenteditable="false">harry</a> great </div>
When in firefox I am unable to remove the a.tgt using backspace. Gets removed in all other browser except firefox
Whats the problem?
This may be helpful for some. I ran into the same problem.
Instead of this:
<div contenteditable="true"> Hey <a class="tgt" contenteditable="false">harry</a> great </div>
You can have this:
<div contenteditable="true"> Hey <a class="tgt" contenteditable="false">harry</a><span class="remove"></span> great </div>
You can use javascript (using jquery in this case) to detect the deletion of .remove and remove your uneditable div at the same time:
// you can wrap this in an if statement and only execute in firefox
$('.remove').on("DOMNodeRemoved", function() {
$(this).prev(".tgt").remove();
});
Hope this helps!
try to wrap <a> html into span tag with attribute contenteditable=true
<div contenteditable="true"> Hey <a class="tgt" contenteditable="false"> <span contentEditable="true">harry</span></a> great</div>