How to avoid Compound Class name error in Page Object? - selenium

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']

Related

How to call remove_column on SALV table?

I want to execute the method remove_column on an instance of cl_salv_column_table but because of its visibility level, I am not able to do so.
Plan:
I already tried inheriting from cl_salv_columns_list and then perform the call inside the remove-method:
CLASS lcl_columns_list DEFINITION INHERITING FROM CL_SALV_COLUMNS_LIST.
PUBLIC SECTION.
METHODS:
remove IMPORTING iw_colname TYPE string.
ENDCLASS.
But apparently my casting knowledge got rusty as I'm not able to figure out an appropriate solution.
This is my current hierarchy - the red arrows show the way I would have to take:
My approach looks like this:
DATA lo_column_list TYPE REF TO lcl_columns_list.
lo_column_list ?= CAST cl_salv_columns_list( lo_columns ).
But it fails with:
CX_SY_MOVE_CAST_ERROR
Source type: \CLASS=CL_SALV_COLUMNS_TABLE
Target type: "\PROGRAM=XXX\CLASS=LCL_COLUMNS_LIST"
Background:
My task is to select all columns of 3 tables (which would be done like SELECT t1~*, t2~*, t3~* ...) as long as their names don't conflict (e.g. field MANDT should only be displayed once). This would require defining a very big structure and kick the size of the selection list to a maximum.
To avoid this, I wanted to make use of the type generated by my inline-declaration. Hiding the individual columns via set_visible( abap_false ) would still display them in the layout manager - which looks really ugly.
Is there any other way to accomplish my target?
Use set_technical( abap_true ) to hide the columns entirely. As for your approach - sorry, inheritance does not work that way - in no statically typed object oriented language that I know. You can't 'recast' an instantiated object to a different class. You would need to modify the framework extensively to support that.

Spaces in CSS Selector-Webdriver

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

Getting from id column name to class name

Given a column name in string format (e.g. "hamburger_id" or "foo_bar_id"), is there a standard way of getting to a class (or class name). In this case, Hamburger or FooBar?
The only way I could think of was this:
column_name[0, column_name.length - 3].camelize.constantize
I can assume (or stipulate) that the variable column_name always contains a string with "_id" at the end and that a corresponding class always exists.
If some one finds it relevant or is curious, I can elaborate on the "why", but I didn't want to clutter up the question with such details.
You could do the following (assuming the traditional Rails example of a Post model that has_many Comment models):
Model.reflect_on_all_associations.select{|a| a.foreign_key == 'column_name'}.first.class_name
This has the advantage that if your class names and foreign keys don't line up, it will still give the correct class name. For instance, if your foreign key is owner_id but the associated model is actually named User, this will return "User" instead of "Owner".
This still feels like a bit of a hack, but that's because it's not very Rails-like to get this information based on a column name - Normally you'd interact with the association directly (using reflect_on_association(:foos)).

Naming convention for multiword view files in Yii?

If I have a view with two or more words, e.g.:
public function actionApprovalQueue()
what is the naming convention of the view file itself?
approval-queue.php
approvalQueue.php
approvalqueue.php
??
The documentation on Conventions only says:
View files should be named after the view name. For example, the index
view is in the index.php file.
which gives no clue about views with two or more words.
When it comes to naming conventions, it comes down to what suits your organisation, or what is followed in your organisation, or what the rest of your team decides. The key is consistency throughout your code base.
I would say go with the dash(hyphen), because variables are generally named $xyzAbc or $xyz_abc. So it would make sense to use approval-queue.php.
Definitely do not go for approvalqueue.php.
Edit: Read more about Yii's conventions here.
Yii recommends naming variables, functions and class types in camel case which capitalizes the first letter of each word in the name and joins them without spaces. Variable and function names should have their first word all in lower-case, in order to differentiate from class names (e.g. $basePath, runController(), LinkPager). For private class member variables, it is recommended to prefix their names with an underscore character (e.g. $_actionList).
Because namespace is not supported prior to PHP 5.3.0, it is recommended that classes be named in some unique way to avoid name conflict with third-party classes. For this reason, all Yii framework classes are prefixed with letter "C".
A special rule for controller class names is that they must be appended with the word Controller. The controller ID is then defined as the class name with first letter in lower case and the word Controller truncated. For example, the PageController class will have the ID page. This rule makes the application more secure. It also makes the URLs related with controllers a bit cleaner (e.g. /index.php?r=page/index instead of /index.php?r=PageController/index).

IntelliJ IDEA: how to find all instance creation of a class?

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.