I'm trying to make a Google userstyle based on Discord's color scheme. Even though I have no programming experience whatsoever, it has been pretty straightforward (Inspect element > Copy-paste to Stylus) but now there's an element that I can't edit. It's the "next" arrow in the video cards that appear in the results for a search. Here it is: The button on the right.
When inspecting it, the selector just shows up as "element", that didn't work, right-clicking and copying the selector (I'm using FIrefox) also didn't work, and using live CSS editors didn't work either.
I'm guessing it's because they use a fake html element called g-right-button. Just change it to div and you'll be fine.
(You can also just make a g-right-button { .. } selector)
You can also see and change properties from inspector.
Below is the HTML snippet of the textbox that i am trying to identify using chromdriver
You could use the following Xpath:
//input[#placeholder="Scan Serial No"]
ry using multiple attributes
//input[#placeholder="Scan Serial No"][contains(#class,'FC2 ELX_UserPrompt')]
For getting selectors there are a few techniques I use.
First I use the built in tools of the Chrome Developer Tools. Open these with ctr+shift+i. Then locate the element you want, ctrl+shift+c then click on the element. This highlights the element you want in the Elements tab. right click on the highlighted element and choose Copy>Copy selector. This will give you a unique css selector for that item. This works well for everything except dynamic elements that have changing id's or locations on the page.
For dynamic elements I use advanced css selectors. where you can leverage the html tag in addition to any css attributes to locate the element. Here is a decent write up on how to use these https://www.smashingmagazine.com/2009/08/taming-advanced-css-selectors/#comments
For you particular element you could do something like input[placeholder='Scan Serial No']
You can use following xpath:
name of class in xpath
//input[#class='FC2 ELX_UserPrompt binding_Screen_cc607e87_a82b_4cac_8c38_939be2ba00ff_SerialNo??']
name of class and placeholder
//input[#class='FC2 ELX_UserPrompt binding_Screen_cc607e87_a82b_4cac_8c38_939be2ba00ff_SerialNo??'][#placeholder='Scan Serial No']
My goals:
Generate a single HTML document with all my output so that it can be copied as a single unit.
Have multiple "pages" within that document that display different parts of the data.
Let the browser's back button do the Right Thing, and support deep-linking.
This is relatively easy to do using the :target pseudo-class to show only the page that I'm looking at (div {display: none} :target {display: block}).
I would like to add two refinements:
A navigation bar that highlights the current page's name.
A main page that appears when there is no fragment identifier (the thing after the #) in the URL.
I have created a solution using empty divs and sibling selectors. The target element (the element whose ID is in the URL fragment identifier) is an empty div, target, and then my CSS says #target1 ~ #page1 { ... } #target1 ~ #link1 { ... }. For a full example see this Fiddle; note that after clicking on the links in the nav bar, the back and forwards browser buttons work as one might reasonably expect (I don't think it's possible to demonstrate deep-linking using jsfiddle).
There are three drawbacks to this solution:
There is a separate selector in my CSS for each page, which can become unwieldy if there are many pages.
The back button works on Chrome and Firefox, but Edge doesn't seem to like this (I haven't tested it anywhere else). My understanding is that the spec is unclear regarding :target and the back button (see also this Webkit bug).
As the question's title says, it feels like I'm abusing... something.
My question is, is there a better way to do what I'm trying to do? I have a slight preference for no JavaScript (mainly because that makes deep-linking more obviously correct).
#Seika85 linked (in a comment) to Navigo, a Javascript router that seems built to do exactly this. I have updated the fiddle to use that instead, which eliminates all the drawbacks I mentioned, at the (minor) expense of having to use (a small bit of) Javascript. Thanks!
new Navigo(null, false)
.on(/target(.)/, function(x) {
$('.active').removeClass('active');
$('#page'+x).addClass('active');
$('#link'+x).addClass('active');
})
I am using Firebug to inspect the elements of a webpage. On the right hand of the page there is a "style" tab that list all the CSS styling for a given tag. These CSS styling are coming from a linked CSS page.
What I am looking to do is somehow copy a set of divs with the CSS hardcoded in the div. This way I can copy and paste the elements and have the exact same styling. Is this possible to do with Firebug or perhaps another tool?
I used IE9 to accomplish this.
Open a page where you want to grab a style in IE9
Press F12 to display Developer Toolbar
In the Developer Toolbar press Find and select "Select element by click"
Then go to "View" > "Source" and select "Element source with style"
I don't know about Firebug, but you could build a script to do it.
List the CSS you want to copy (every property you believe is required to make it portable) and then loop through in JS and getComputedStyle(). Then build a ; delimited list of property:value pairs, and assign it to the style attribute if your element and all children.
This doesn't look like an easy task - and you will no doubt run into problems.
I'm not sure what exactly you're trying to do here but are you trying to apply the same style to multiple elements (divs)? If so you should use a css class. So your html will be
<div class="myClass"></div>
<div class="myClass"></div>
<div class="myClass"></div>
and css will be
.myClass
{
height:whatever;
width:whatever;
etc
}
I was wondering if there is such an addon in firefox where you can test out css paths to check if they are finding the correct element? I was looking for something similar to xpather for xpath locations.
Edit 2019-12-04:
The firefinder addon no longer exists, but you can use the developer console (press F12), and the $$ function to get elements matching a selector, eg. to select all divs: $$('div')
Old answer:
FireFinder does exactly what you are looking for. You can evaluate either CSS, or XPath expressions, it will list the matching elements, and also draw a red border around them.
Yes you can go for FireBug, a versatile Firefox web development add-on.
(source: getfirebug.com)
To test a CSS selector, go to the "Console" tab and enter a command in the bottom form (more info on how to find the command line).
Inside the command line use the $$("your CSS selector") syntax to test CSS selectors, explained in more detail here. For example use this command to select everything:
$$("body")
Here's how to use the built in CSS query selector in Firefox:
Go to Tools > Web Developer > Web Console
Also, you could press ctrl shift i in Windows/Linux, or cmd opt i in Mac.
Type in your CSS selector (using traditional $$() syntax) at the very bottom left corner.
The object node list will appear on the right hand panel of the console.
$$('div')
[object NodeList]
$$('div').length
42
This is handy for Selenium Webdriver instances of Firefox, where having an extension isn't feasible.
Try firebug. http://getfirebug.com/
Not sure if this helps. Try Firebug. Allows you to select an item, and see what it's css path is, as well as the css currently being applied.
Can do some experimentation in the html/css right in the browser.
FireFinder is good, but I started with and prefer FirePath for Firebug. It works similarly, but can give you an expanded view of the HTML around the matching elements w/o need to click inspect, FriendlyFire, etc.
The field where you test the locator also has syntax checker where field turns red if syntax is bad. Just click eval to test the locator and matches show below with additional HTML around the matching elements.
But for testing CSS locator, you'd want the drop down option of "Sizzle" rather than CSS in FirePath. The CSS option only works for simple CSS selectors, complex ones only work under Sizzle (l mode, such as:
div.namedService.photoService > div.photoBrowserContainer:nth-child(3) > div.albumName:contains('someName')
Selenium IDE 1.0.11 released has inbuilt CSS locator builder
The DOM standard function document.querySelectorAll is what you want, modern browser all support it. See the document
https://developer.mozilla.org/en-US/docs/DOM/Document.querySelectorAll
You can call it in built-in web console. In console there is a shortcut $$, call it like $$('div a').
I like firebug because it can click to scroll to view the element. It also can test in 'CSS' panel.
The 'Find' button in Selenium IDE is very useful for this. It uses the same method to locate elements as your tests will, so can be used to locate elements using any of the supported strategies.
jQuery
With jQuery you could easily add a large red border to an element using the selector.
$(document).ready(function(){
$('#your-css-selector').css('border', '5px solid red');
});
Firebug (https://addons.mozilla.org/en-US/firefox/addon/1843) or Web Developer Toolbar (https://addons.mozilla.org/en-US/firefox/addon/60). Both show path.
Firefinder is great for testing selectors. However, if also you want to obtain the CSS selector for an element try SelectorGadget.
I've found FirePath to be really great, it lets you look up not only CSS but xPath as well. Wish there was something similar for Chrome and IE, but alas!