When i am trying to locate this below div with class name,i am unable to find,
<div class="large 20 columns">..</div>
i tried dr.findElement(By.cssSelector("div.large.20.columns']"));but unable to locate.
Please let me know, is there any way to locate class name with space using CSS Selector.
The problem here is that the "20" class expects you to use a class selector like .20, which is not a valid selector as CSS idents must not start with a digit.
This should work:
dr.findElement(By.cssSelector("div.large.\\20.columns"));
You also have '] at the end of your selector string for some reason. Was this a leftover from an attempt at using an attribute selector? If so, you should be able to get away with this as well but only if the page is guaranteed to have the class names in that exact order:
dr.findElement(By.cssSelector("div[class='large 20 columns']"));
Relying on layout-oriented class names like large is not a good idea in general. I would use just:
div.columns
If this is not enough to uniquely identify the element, I would additionally check for other attributes, specific parent, child or adjacent elements.
You are not able to find the element because of invalid class name. CSS class can not start with a number(20 in your case). Also, CSS class names can not have spaces as they are considered to be different classes.
Please refer to the explaination provided here and here
Related
Trying to find any method name in my project matching a specific sub-string.
The example I'm currently looking for is "domain", so I'd want to see getDomain(), setDomain(), domainThing(), etc. in the results. Looking for static/instance methods of any visibility.
Find Symbol (Ctrl+Alt+Shift+N) comes close, but there's too many classes and fields cluttering up the results. Is there a way to restrict Find Symbol to only methods? Or at least group the results by symbol type?
Structural Search might be the answer, but it's comically unusable interface and documentation have defeated me once again.
SSR is the way to go. There is an existing template for the methods of the class you can start with.
Click on $Method$, Edit filters, Add filter, Text.
Enter regex to match your methods, for example .*domain.*.
Uncheck the Match case checkbox.
The final result should look like this:
I'd like to choose class of an element bases on importance:
<strong> Importance:
<span :class="importance ? (calculate class here)">
</span> {{someText}}
</strong>
Let's say the class vlue should be imp0 ,imp1,imp2, imp3 or imp4, depending on whether importance equals 0,1,2,3 or 4.
You may ask why not calculate the value in a method function?
The answer is: to keep the class value synced with the result of a separate method which also gets importance as input parameter after the class is rendered.
So wondering how can I achieve this?
Update: I managed to do it with a convulted ternary conditional:
:class="importance==0 ? 'imp0': (importance==1? 'imp1': (importance==2 ? 'imp2': (importance==3 ? 'imp3': 'imp4')))
but wondering if there is a more clean way to do so?
If your mapping is that direct, you can let it go with simple expression:
:class="'imp' + importance"
... but I strongly advise you to at least consider it a technical debt. Remember, you can use any attribute in your CSS selector, not just classes.
is there a way to search for all occurences of subclasses of a particular class ?
Say I have a class AbstractItem and I have got a lot of implementations of this AbstractItem class. Now I want to know where all subclasses are used.
Can I search for all occurences of all subclasses with a structural search pattern in Intellij IDEA ?
Thanks,
Detlef
The easiest way is use the following:
Search template:
$A$
Set Expression type (regexp) to AbstractItem and check the Apply constraint within type hierarchy checkbox (under Edit Variables...).
This will find all expressions with type or subtype of AbstractItem.
When I try to use the class name that having space class = "country name" in page object, I'm getting:
Compound class names not permitted Selenium::WebDriver::Error::UnknownError)
How can I use the class name that having space.
Eg:
class = "country name"
Use a CSS selector instead:
.country.name
The important thing to note is that this example is wrong! If "country name" is meant as a name of a country, that is. Class names can't have spaces in them. In fact, the class attribute is a space-separated list of classes. That means that if you have a class country name, it's not one class, it's two different classes your element belongs to - the first is country, the second is name!
Therefore, fix your classes, if they're wrong. If they're not, use a CSS selector, it's the only reliable way to match multiple classes (apart from a very long and complicated XPath expression). Don't use trivial XPath expressions or CSS selectors with naive attribute comparison (//*[#class='country name'] or *[class='country name']), that's just plain wrong.
You can use with this
By.cssSelector("*[class^='classname']");
^ is for if you entering beginning of the class name,
$ is for if you entering ending of the class name usage example below with sample class name: tech random corner text_left
By.cssSelector("*[class^='tech']");
By.cssSelector("*[class$='text_left']");
You can use one of these class names, for example
:class => 'country'
or
:class => 'name'
if it can't help you then you should switch to use other type of selector :css or :xpath
But note that in case of :css you write:
:css => '.country.name'
and in case of :xpath:
:xpath => '//div[#class='country code']
both should work
If you have class names which have spaces in them you will get this error. One way of avoiding is creating an xpath for identifying the element. If you show the html I can create the xpath. Also try using class names as multiple objects will have the same class name.
You will have to either remove the space from the class name, in which case Selenium should still in theory find the elements you need or, use a CSS selector and combine it with a period/full stop to concatenate the class names together.
i.e, using a CSS selector to target this:
<div class="country code"></div>
You could use:
div.country.code
or you could make your selector a bit more elaborate:
div[class='country code']
abstract class Base {}
class A extends Base
class B extends Base
How do I find all places in the code that create Base? (that is, have either new A() or new B())
UPDATE
To make it clear, the above is just and example. I'm interested in a way of searching for object creation of any class, including 3rd party classes that I don't control.
Using Structural Search (Edit -> Find -> Search Structurally):
Create a template: new $Type$($P$)
Edit Type variable: type Base in the text field, check 'Apply constraint within type hierarchy', check 'This variable is target of the search'
Edit P variable: type .* in the text field, set Minimum count to 0, check Unlimited under Maximum count.
Voila!
IttayD if I have understood correctly your latest update, what I normally do (IntelliJ 9.0.4) if I have a similar need to yours is Right click on class name and do "Find Usages" and this will list results in the form of usage categories,
Variable declaration
New Instance creation, to name a few.
As far as I'm aware I do not think there is a specific option/selection choice to fulfill such a usage search check. Thanks
You can create empty default constructor of Base and press Ctrl+Alt+H (Hierarchy Callers). Then you'll see all creations of A and B in as a tree.