By is not a function in selenium nightwatch - selenium

I could not use the default By commands in selenium. Below is my script
driver.findElement(By.xpath("//*[#id='lotstatus_q']/div/table/tbody/tr"));
my script is failing and the result is this:By is not a function
is there any other items that I need to install?
All other By commands are not functioning.

I think you made a mistake, you cannot directly access to Selenium API from Nightwatch.js !
Nightwatch is just an override of the WebDriver Wire Protocole (exposed by Selenium as REST API)
https://code.google.com/p/selenium/wiki/JsonWireProtocol
But you can use XPath selectors with Nightwatch:
client.useXpath().waitForElementVisible("//*[#id='lotstatus_q']/div/table/tbody/tr")
Read the doc about XPath: http://nightwatchjs.org/guide#using-xpath-selectors

You cannot apply the regular Java patterns with NightWatchJS and also NightWatch Apis does not work that way...
Please see the API docs on how you can use http://nightwatchjs.org/api#commands
I think you are trying to do
browser.elements("css locator" , "value of your css", function (result){
// here result is the return from calling selenium wire protocol /elements
// Using the identifier of your CSS locators
})

Related

nightwatch xpath selector not working

I'm currently working on a node/express.js app for which I'm writing some e2e tests in nightwatch. Today I hit a roadblock while trying to search for an element using the XPath locator strategy. Basically I can search for elements using any of the following:
//div[#data-pino-name='userIdSection']
//input[#name="password"]
//input[#name="username"]
//button[#data-pino-name="submit"]
//a[#data-pino-name="cancel"]
By the way, all of the selectors above work fine using the chrome tools.
However, using the following:
//pre[#data-pino-name="requiredErrorMessage"]
doesn't work at all. I'm surprised since I expected the <pre> tag to be treated the same as any other html tag. However, the test returns a "element was not found" for all elements with the pre tag.
Anyone guidance would be appreciated.
You can follow this approach in writing XPath based on your scenario
//div[#data-pino-name='userIdSection']/pre
//div[#data-pino-name='userIdSection']/pre[#data-pino-name="requiredErrorMessage"]

How to execute JavaScript in Robot Framework

Below is my code. When I run this, it shows a WebDriverException. How do I execute JavaScript code in Robot Framework?
This, return $(arguments[0]).data('${ToolTip}').options.title code is doing well in -java Selenium web driver.
Mouse Over ${CreateTask}
Execute JavaScript return $(arguments[0]).data('${ToolTip}').options.title
From http://rtomac.github.io/robotframework-selenium2library/doc/Selenium2Library.html#Execute%20Javascript:
Note that, by default, the code will be executed in the context of the
Selenium object itself, so this will refer to the Selenium object. Use
window to refer to the window of your application, e.g.
window.document.getElementById('foo').
So
Mouse Over ${CreateTask}
Execute JavaScript return window.$(arguments[0]).data('${ToolTip}').options.title
Assuming there is some library (jQuery most probably) that actually understands the $ shorthand.
arguments[0] normally refers to arguments passed to your script.
Selenium2Library's Execute JavaScript calls
webdriver.execute_javascript and does not pass any arguments to it. arguments[0] is therefore undefined.
See Is there a way to provide arguments to "Execute JavaScript" in Robot Framework? for a workaround.
Use any one method from below options
Execute Javascript document.getElementById('authUser').value='admin'
${ele} Get WebElement id=clearPass
Execute Javascript arguments[0].value='pass'; ARGUMENTS ${ele}
Execute Javascript alert(arguments[0]); ARGUMENTS 123
Execute Javascript document.evaluate("//*[text()='Patients']",document.body,null,9,null).singleNodeValue.click();
Execute Javascript document.querySelector('[data-bind="click: changePassword"]').click();
${ele} Get WebElement //*[text()='Logout']
Execute Javascript arguments[0].click(); ARGUMENTS ${ele}

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

Testing for CSS Selenium locators from the browser

In general, when I want to test the validity of a locator to be used in Selenium, I test it using the Firebug console.
i.e., I write: $$("a#someLink") in the Firebug console and the corresponding link becomes highlighted in Firefox.
However, if I test in Firebug for a locator like:
table#someTable tr:nth-of-type(2) td:nth-of-type(2)
Firebug doesn't show anything... Even though the locator works fine from Selenium...
I guess Selenium uses some 'hacks' for CSS locators, which Firebug does not understand...
Is there any way around it? Would using Xpath locators allow me to test for those kinds of locators?
Thank you very much
Firebug has an extension called FireFinder, which allows you to test xpath or css locators and it shows all the matches on the page. Here's a link.

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.