Code works for FirefoxDriver but NOT in HtmlUnitDriver - webdriver

I need to click on a link pointed by following xPath : html/body/div[2]/ul/li[9]/a (generated using firepath) The corresponding Html snippes is as following :
< a href="/abb/logout">Logoff
My code is like this :
HtmlUnitDriver driver= new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);
WebElement logoffElement = (new WebDriverWait(driver, 10))
.until(new ExpectedCondition<WebElement>(){
#Override
public WebElement apply(WebDriver d) {
return d.findElement(By.xpath("html/body/div[2]/ul/li[9]/a"));
}});
logoffElement.click();
The above code is working for Firefoxdriver but not in HtmlUnitdriver. HtmlUnitdriver gives following error :
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate a node using html/body/div[2]/ul/li[9]/a
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.21.0', revision: '16552', time: '2012-04-11 19:08:38'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_23'
Driver info: driver.version: HtmlUnitDriver
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByXPath(HtmlUnitDriver.java:802)
at org.openqa.selenium.By$ByXPath.findElement(By.java:344)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1244)
at org.openqa.selenium.htmlunit.HtmlUnitDriver$5.call(HtmlUnitDriver.java:1)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:984)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:1241)
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:396)
at com.nike.automation.Task$1.apply(Task.java:70)
at com.nike.automation.Task$1.apply(Task.java:1)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:201)

HtmlUnitDriver is a fake browser, which can't handle javascript and lacks of features which normal browsers have. FirefoxDriver or ChromeDriver use real browsers.

//html/body/div[2]/ul/li[9]/a -- Absolute XPath.
It is not advisable to use Absolute XPath. Use Relative XPath so that it will be working in all browsers.
Thanks!

Related

Using Http source throws org/wso2/transport/http/netty/contract/config/ListenerConfiguration error

Using http source, I'm trying to insert 3 parameters into a stream, which I will use as an input to other streams.
#App:name("SiddhiSample")
#App:description("Sample http")
#source(type='http', receiver.url='http://0.0.0.0:8008/event', #map(type = 'json', #attributes(a='$.a', b='$.c', c='$.c')))
define stream InputStream(a string, b string, c string);
I'm getting this error at the line '#source' -
Caused by: org.wso2.siddhi.core.exception.SiddhiAppCreationException: Error on 'SiddhiSample' # Line: 5. Position: 143, near '#source(type='http', receiver.url='http://0.0.0.0:8008/event', #map(type = 'json', #attributes(a='$.a', b='$.b', c='$.c')))'. org/wso2/transport/http/netty/contract/config/ListenerConfiguration
at org.wso2.siddhi.core.util.ExceptionUtil.populateQueryContext(ExceptionUtil.java:43)
at org.wso2.siddhi.core.util.parser.helper.DefinitionParserHelper.addEventSource(DefinitionParserHelper.java:370)
at org.wso2.siddhi.core.util.SiddhiAppRuntimeBuilder.defineStream(SiddhiAppRuntimeBuilder.java:114)
at org.wso2.siddhi.core.util.parser.SiddhiAppParser.defineStreamDefinitions(SiddhiAppParser.java:307)
at org.wso2.siddhi.core.util.parser.SiddhiAppParser.parse(SiddhiAppParser.java:223)
at org.wso2.siddhi.core.SiddhiManager.createSiddhiAppRuntime(SiddhiManager.java:65)
at org.wso2.siddhi.core.SiddhiManager.createSiddhiAppRuntime(SiddhiManager.java:74)
at org.wso2.carbon.stream.processor.core.internal.StreamProcessorService.deploySiddhiApp(StreamProcessorService.java:100)
at org.wso2.carbon.stream.processor.core.internal.StreamProcessorDeployer.deploySiddhiQLFile(StreamProcessorDeployer.java:93)
... 14 more
Caused by: java.lang.NoClassDefFoundError: org/wso2/transport/http/netty/contract/config/ListenerConfiguration
at org.wso2.extension.siddhi.io.http.source.util.HttpSourceUtil.getListenerConfiguration(HttpSourceUtil.java:177)
at org.wso2.extension.siddhi.io.http.source.HttpSource.initSource(HttpSource.java:478)
at org.wso2.extension.siddhi.io.http.source.HttpSource.init(HttpSource.java:415)
at org.wso2.siddhi.core.stream.input.source.Source.init(Source.java:69)
at org.wso2.siddhi.core.util.parser.helper.DefinitionParserHelper.addEventSource(DefinitionParserHelper.java:365)
... 21 more
This was working previously - I was able to pass data to the stream via curl commands. Can someone help me understand what's wrong?
I'm using WSO2SP 4.3.0 and siddhi-io-http-1.1.2.jar
WSO2SP 4.3.0 is not supporting siddhi-io-http-1.1.2.jar, please use WSO2SP 4.4.0 instead, and WSO2SP 4.4.0 will also work with the current latest version of siddhi-io-http-1.2.1 .jar
https://mvnrepository.com/artifact/org.wso2.extension.siddhi.io.http/siddhi-io-http/1.2.1

Geb withFrame - "call function result missing 'value'"

I'm new to using withFrames in Geb, and I am trying to follow the examples in the Book of Geb.
I am trying to get my code to enter text and push a button within a frame.
The preferred way is to define the frame element inside your containing page, but for now I just want to see what I am doing wrong in my withFrame call.
def "Write and Post a Small Comment" () {
when:
MyBlogSpot bs = to MyBlogSpot
then:
bs.readMoreLink.click()
withFrame("comment-editor"){ // <---- this is the line 16 in the error statement
$('#commentBodyField') << "my text"
$("button", name:"postCommentSubmit").click()
}
}
The above is the spec.
The element I am trying to reach is:
<iframe allowtransparency="true" class="blogger- iframe-colorize blogger-comment-from-post" frameborder="0" height="194px" id="comment-editor" name="comment-editor" src="https://www.blogger.com/comment-iframe.g?blogID=3577645066754224503&postID=6815587395142211832&blogspotRpcToken=2994523#%7B%22color%22%3A%22rgb(34%2C%2034%2C%2034)%22%2C%22backgroundColor%22%3A%22rgb(255%2C%20255%2C%20255)%22%2C%22unvisitedLinkColor%22%3A%22rgb(204%2C%20102%2C%2017)%22%2C%22fontFamily%22%3A%22Arial%2C%20Tahoma%2C%20Helvetica%2C%20FreeSans%2C%20sans-serif%22%7D" width="100%" data-resized="true"></iframe>
No matter what arguments I use for withFrame - even if I use withFrame(2) after checking the browser debugger tool - the error I get when running the test is:
at CommentSpec.Write and Post a Small
Comment(CommentSpec.groovy:17)
Caused by:
org.openqa.selenium.WebDriverException: unknown error: call function result missing 'value'
(Session info: chrome=70.0.3538.77)
(Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T15:28:36.4Z'
System info: host: 'GUY-HP', ip: '192.168.1.2', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=XP, acceptSslCerts=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, platformName=XP, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a), userDataDir=C:\Users\Guy\AppData\Local\Temp\scoped_dir12868_17851}, takesHeapSnapshot=true, pageLoadStrategy=normal, unhandledPromptBehavior=, databaseEnabled=false, handlesAlerts=true, version=70.0.3538.77, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}]
Session ID: da4a617e55935af5a32b5c7c17213231
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:82)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.frame(RemoteWebDriver.java:912)
at geb.frame.DefaultFrameSupport.executeWithFrame(DefaultFrameSupport.groovy:57)
at geb.frame.DefaultFrameSupport.withFrame(DefaultFrameSupport.groovy:36)
at geb.Page.withFrame(Page.groovy:120)
at geb.Browser.methodMissing(Browser.groovy:217)
at geb.spock.GebSpec.methodMissing(GebSpec.groovy:60)
... 1 more
If there is any other code I need to paste in, please let me know. TIA!
This looks like a problem with version compatibility between the binaries.
The error shows your are using
chrome=70.0.3538.77
Driver info: chromedriver=2.32.498550
You want to download the latest chromedriver 2.43 which works with your version of Chrome. See here for compatible versions: Chrome Drivers

QBS: Explicitly setting qbs.profiles inside Products causing build to fail

My use-case is this:
I have a static library which I want to be available for some profiles (e.g. "gcc", "arm-gcc", "mips-gcc").
I also have an application which links to this library, but this applications should only build using a specific profile (e.g. "arm-gcc").
For this I am modifying the app-and-lib QBS example.
The lib.qbs file:
import qbs 1.0
Product {
qbs.profiles: ["gcc", "arm-gcc", "mips-gcc"] //I added only this line
type: "staticlibrary"
name: "mylib"
files: [
"lib.cpp",
"lib.h",
]
Depends { name: 'cpp' }
cpp.defines: ['CRUCIAL_DEFINE']
Export {
Depends { name: "cpp" }
cpp.includePaths: [product.sourceDirectory]
}
}
The app.qbs file:
import qbs 1.0
Product {
qbs.profiles: ["arm-gcc"] //I added only this line
type: "application"
consoleApplication: true
files : [ "main.cpp" ]
Depends { name: "cpp" }
Depends { name: "mylib" }
}
The app build fails. Qbs wrongly tries to link to the "gcc" version of the library instead of the "arm-gcc" version, as you can see in the log:
Build graph does not yet exist for configuration 'default'. Starting from scratch.
Resolving project for configuration default
Setting up build graph for configuration default
Building for configuration default
compiling lib.cpp [mylib {"profile":"gcc"}]
compiling lib.cpp [mylib {"profile":"arm-gcc"}]
compiling lib.cpp [mylib {"profile":"mips-gcc"}]
compiling main.cpp [app]
creating libmylib.a [mylib {"profile":"gcc"}]
creating libmylib.a [mylib {"profile":"mips-gcc"}]
creating libmylib.a [mylib {"profile":"arm-gcc"}]
linking app [app]
ERROR: /usr/bin/arm-linux-gnueabihf-g++ -o /home/user/programs/qbs/usr/local/share/qbs/examples/app-and-lib/default/app.7d104347/app /home/user/programs/qbs/usr/local/share/qbs/examples/app-and-lib/default/app.7d104347/3a52ce780950d4d9/main.cpp.o /home/user/programs/qbs/usr/local/share/qbs/examples/app-and-lib/default/mylib.eyJwcm9maWxlIjoiZ2NjIn0-.792f47ec/libmylib.a
ERROR: /home/user/programs/qbs/usr/local/share/qbs/examples/app-and-lib/default/mylib.eyJwcm9maWxlIjoiZ2NjIn0-.792f47ec/libmylib.a: error adding symbols: File format not recognized
collect2: error: ld returned 1 exit status
ERROR: Process failed with exit code 1.
The following products could not be built for configuration default:
app
The build fails only when selecting one profile in the app.qbs file, and this profile should not be the first profile in the qbs.profiles line in the lib.qbs file.
When selecting two or more profiles - the build succeeds.
My analysis:
I think this problem is related to multiplexing:
The lib.qbs contains more than one profile. This turns on multiplexing when building the library, which, in turn, adds additional 'multiplexConfigurationId' to the build-directory name (moduleloader.cpp).
The app.lib contains only one profile, so multiplexing is not turned on and the build-directory name does not get the extra string.
The problem can be solved by changing the code (moduleloader.cpp) so that multiplexing is turned even if there is only one profile i.e. with the following patch:
--- moduleloader.cpp 2018-10-24 16:17:43.633527397 +0300
+++ moduleloader.cpp.new 2018-10-24 16:18:27.541370544 +0300
## -872,7 +872,7 ##
= callWithTemporaryBaseModule<const MultiplexInfo>(dummyContext,
extractMultiplexInfoFromProduct);
- if (multiplexInfo.table.size() > 1)
+ if (multiplexInfo.table.size() > 0)
productItem->setProperty(StringConstants::multiplexedProperty(), VariantValue::trueValue());
VariantValuePtr productNameValue = VariantValue::create(productName);
## -891,7 +891,7 ##
const QString multiplexConfigurationId = multiplexInfo.toIdString(row);
const VariantValuePtr multiplexConfigurationIdValue
= VariantValue::create(multiplexConfigurationId);
- if (multiplexInfo.table.size() > 1 || aggregator) {
+ if (multiplexInfo.table.size() > 0 || aggregator) {
multiplexConfigurationIdValues.push_back(multiplexConfigurationIdValue);
item->setProperty(StringConstants::multiplexConfigurationIdProperty(),
multiplexConfigurationIdValue);
This worked for my use case. I don't know if it make sense in a broader view.
Finally, the questions:
Does it all make sense?
Is this a normal behavior?
Is this use-case simply not supported?
Is there a better solution?
Thanks in advance.
Yes, the default behavior with multiplexing is that the a non-multiplexed product depends on all variants of the dependency. In general, there is no way for a user to change that behavior, but there should be.
However, luckily for you, profiles are special:
Depends { name: "mylib"; profiles: "arm-gcc" }
This should fix your problem.

runningApplications deprecated in Mavericks, or what?

Compiling the same project under OSX 10.8.5 and 10.9, I have found that runningApplications does not work with the same function as mentioned below:
-(void)killProcessesNamed:(NSString*)appName
{
for ( id app in [[NSWorkspace sharedWorkspace] runningApplications] )
{
if ( [appName isEqualToString:[[app executableURL] lastPathComponent]] )
{
[app terminate];
}
}
}
Looking at NSRunningApplication.h I've found this:
- (NSArray *)runningApplications NS_AVAILABLE_MAC(10_6);
I do not know if it is really deprecated, but I get a warnings about multiple ambiguous method found in NSRunningApplication.h and also in NSTask.h both regarding:
- (BOOL)terminate; // in NSRunningApplication.h
- (void)terminate; // in NSTask.h
therefore the warning disappears if I change terminated in forceTerminate:
//[app terminate];
[app forceTerminate];
The problem is that in Mavericks does not want to kill the process/app indicated.
To be more clear, the above warning appears only if the project is under ARC.
thanks

Does selenium 2.0 supports dynamic string value for By.xpath

I am trying to click on checkbox using following code:
String podID = "'microsoft-gallery-clipbox-pod-" + podId.substring(3)+"'";
driver.findElement(By.xpath("id(" + podID + ")")).click();
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"id('microsoft-gallery-clipbox-pod-15423100')"}
System info: os.name: 'Windows 7', os.arch: 'x86', os.vers
When i run following code it works fine:
driver.findElement(By.xpath("id('microsoft-gallery-clipbox-pod-15424100')")).click();
Any idea why the first code doesnt works?
The two IDs you show are not identical (the numbers at the end are different):
microsoft-gallery-clipbox-pod-15423100
microsoft-gallery-clipbox-pod-15424100
Could that be the problem?
I would try using the following:
String podID = "microsoft-gallery-clipbox-pod-" + podId.substring(3);
driver.findElement(By.xpath("//*[#id='" + podID + "']")).click();

Resources