How to modify css attribute without using javascript in Selenium Webdriver - selenium

Is there a way to modify css attribute without using selenium's driver.execute_script?

No, there is not.
Selenium is meant to mimic user interactions with the browser. Setting CSS attributes is not part of the normal user interaction with a browser.
If you wish to modify a CSS attribute, you will need to use execute-script.

Related

How to inject CSS into webkit?

On Linux I'm creating a webkit window which needs to display a certain URL.
I'm doing that like the following:
GtkWidget *main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
// Create a browser instance
WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
// Put the browser area into the main window
gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView));
// Load a web page into the browser instance
webkit_web_view_load_uri(webView, "http://example.com");
// Make sure that when the browser area becomes visible, it will get mouse
// and keyboard events
gtk_widget_grab_focus(GTK_WIDGET(webView));
// Show the result
gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
gtk_widget_show_all(main_window);
However, I need to inject some CSS into this to hide a certain checkbox.
How do I inject CSS into the DOM.
I see that I can get the dom like
WebKitDOMDocument *dom = webkit_web_view_get_dom_document(webView);
But from here I can't see how to inject the CSS.
It sounds like the webkit_web_view_run_javascript() answer was a good solution to your specific problem, since you only needed to hide one checkbox.
To answer the general problem of how to inject arbitrary CSS: if you're using a recent version of WebKitGTK+, create a WebKitUserContentManager, call webkit_user_content_manager_add_stylesheet(), and then pass the WebKitUserContentManager when creating your WebKitWebView, either using webkit_web_view_new_with_user_content_manager() or by using g_object_new() manually if you need to set multiple construct-only properties.
Unrelated warning: webkit_web_view_get_dom_document() was removed in WebKitGTK+ 2.6. (The DOM API is only accessible via web process extensions nowadays.) You are using an old, insecure version of WebKitGTK+!
Its not clear which Webkit GTK version you are using, however concepts essentially remain same for both versions. For webkit version 2, its slightly more complicated as DOM manipulation is done on extension side.
You need to reach to the desired element - either by id e.webkit-dom-document-get-element-by-id or by name. This will return you instance of WebElement. If you use by name call, please be ware that there could be multiple elements with same name
From here you can either set the style by setting appropriate style attribute webkit_dom_element_set_attribute or other variations that can deal with styles and css rules.
Or you can take easy option and just execute the javascript that does the same thing by calling webkit_web_view_run_javascript

Selenium css selectors on element with huge list of classes

I've been working on automation of a product that uses Dojo. The html I'm working with is very messy.. I need to click on div that has following css selector
div.dijit.dijitReset.dijitInline.dijitLeft.dijitTextBox.dijitComboBox.dijitDateTextBox.dijitValidationTextBox.dijitTextBoxError.dijitComboBoxError.dijitDateTextBoxError.dijitValidationTextBoxError.dijitError
I'm using firefinder plugin in Firefox and it can see the element all the time, out of 2 chrome plugins I have (CSS selector tester and CSS and Xpath checker) only the first one can find the element.
When I run my selenium code I get org.openqa.selenium.NoSuchElementException.
I tried selecting classes with . and with [class=".."] as well and both failed.
Is there some selenium limitation on how many classes you can have assigned to your element before it stops seeing an element? What stable approach can I use to make my tests work?
Use FirePath plugin in firefox and look for unique classes so you only have 1 unique selector. Also look up CSS selectors, they will help you in the long run
http://www.w3schools.com/cssref/css_selectors.asp

How can I write Selenium test case for a specific GWT Widget?

I'm very new to Selenium. I want to write Selenium test cases for GWT widget. I can wirte test case for HTML elements since they have id, but i'm not able to do the same in GWT. I want to test widgets such as textboxes, images, listbox etc.
Can anyone help me?
Thanks in advance,
Gnik
Now I set debugId for the GWT widgets. Using that Id I can access the elements and test.
For eg. In UiBinder set id as <g:TextBox ui:field="textBox" debugId="userBox"
In the java code, textBox.ensureDebugId("userBox");
I can access these widgets in Selenium as follows,
selenium.type("gwt-debug-userBox", "testing");
I don't know if selenium is the right tool to test GWT Widgets, I think there are special tools for that.
With Selenium you can automate the browser. If GWT doesn't provide ids for its html elements there are various other ways to locate your elements. For example you can use xpath or css selectors. Just check the Selenium documentation.
But again, be careful about what you want to test. You don't want to test that GWT Widgets create a proper Web application, that is done already. You probably want to use a special GWT test tool where you test the java side of your widget.

How to get the content of CKeditor using WebDriver

I'd like to be able to test the content in CKeditor using webdriver.
However there are some hurdles; firstly CKeditor uses Iframes, and there are several Iframes on the page, so not sure how to switch reliably to it using WebDriver as they don't have specific names.
In addition, the content inside the editor is within a <body></body> tag inside the iframe. I'm not sure how to get WebDriver to return the content reliably.
Has anyone actually tried to do this in their tests? If so, how did you achieve it?
Thanks.
You can use the CKEditor api and execute javascript. Not sure which selenium driver you are using but here is the java script you can use to get the HTML for:
"return CKEDITOR.instances['youreditoridhere'].getData();"
u may refer this
http://bharath-marrivada.blogspot.com/2012/03/fckeditor-switch-activeelement.html
hopes this help ;D

Using Selenium IDE, how to test CSS style information

I am testing a plugin which makes changes to the CSS of HTML elements – how can I use Selenium commands to verify/test these CSS changes?
You can use CSS classes and then check if the element has a specific class.
In Selenium IDE :
Command: assertAttribute
Target: document.getElementById('header')[0]#class
Value: myHeader
Unfortunately Selenium IDE is mis-sold as a Record and Replay tool. Selenium IDE is actually a record, tweak and replay tool.
The tweak part is because the IDE can't record everything that you want. I recommend that you create your test from scratch by hand to get it to check the elements CSS.