ERROR: Unable to locate element - xpath

I have to test a dynamic app using the ZK framework and Selenium does not identify the id's from the different elements, so can't enter text in the textboxes or select an element in a list (elements from a database)
Whatever I use (xpath or css selector) nothing works, always the same error
Does anyone know how can I fix my problems?
I'm using Selenium IDE 1.9.0
Netbeans IDE 7.1.1
And Firefox 16.0.2
Thanks
The Html code is:
button id="zc_subdossierzulButton_8" class="butt z-button-os" style="border-style: solid;border-width: 1px;border-color: #ED0000;" type="button">Rechercher
And the Java code i tried is:
driver.findElement(By.cssSelector("zc_subdossierzulButton_8.butt"));
don't work
this:
driver.findElement(By.cssSelector("butt z-button-os"));
don't work
and this:
String cssSelector = "[class='butt z-button-os']";
driver.findElement(By.cssSelector(cssSelector)).clear();
driver.findElement(By.cssSelector(cssSelector)).sendKeys("c");

Please go through the following documentation and try using different options like
driver.findElement(By.id("coolestWidgetEvah"));
OR
driver.findElements(By.className("cheese"));
OR
driver.findElement(By.tagName("iframe"));
OR
driver.findElement(By.name("cheese"));
OR
driver.findElement(By.linkText("cheese"));
OR
driver.findElement(By.partialLinkText("cheese"));
OR
driver.findElements(By.xpath("//input"));
http://seleniumhq.org/docs/03_webdriver.html#locating-ui-elements-webelements

Related

Unable to automate mouse actions using appium for mac driver

i am automating a mac application using appium. I am not able to go down the in application page. i have tried couple of ways, didn't succeed.
http://appium.io/docs/en/commands/interactions/mouse/moveto/
when i use above option, i am not able find the element itself, but the element is very much available in page.
String xpath=""/AxApplication[#AxTitle='Learning']/AXWindow/AXScrollArea[#AXDescription='My Learning']/AXList[#AXDescription='My Learning']/AXList[#AXDescription='Added by Me']/AXButton[#contains(name,'See All')]";
Actions action = new Actions(adriver);
WebElement elemnt=adriver.findElement(By.xpath(xpath));
action.moveToElement(elemnt, 500, 900);
action.release();
action.perform();
Please suggest.

Scrapy: '//select/option' xpath not yielding any results

I've been trying Scrapy and absolutely love it. However, one of the things I'm testing it in does not seem to work.
I'm trying to scrape a page (apple.com, for example) and save a list of the keyboard options available, using the simple xpath
//select/option
When using Chrome console, the website below comes back with an array of selections that I can easily iterate through, however, if I use scrapy.response.xpath('//select/option') via the scraper, or via the console, I get nothing back from it.
My code for the scraper looks a bit like the below (edited for simplicity)
import scrapy
from scrapy.linkextractors import LinkExtractor
from lxml import html
from apple.items import AppleItem
class ApplekbSpider(scrapy.Spider):
name = 'applekb'
allowed_domains = ['apple.com']
start_urls = ('http://www.apple.com/ae/shop/buy-mac/imac?product=MK482&step=config#', )
def parse(self, response):
for sel in response.xpath('//select/option'):
item = AppleItem()
item['country'] = sel.xpath('//span[#class="as-globalfooter-locale-name"]/text()').extract()
item['kb'] = sel.xpath('text()').extract()
item['code'] = sel.xpath('#value').extract()
yield item
As you can see I'm trying to get the code and text for each option, along with the site "Locale Name" (country).
As a side note, I've tried with CSS selectors to no avail. Anyone knows what I'm missing?
Thanks a lot in advance,
A
The problem is the usage of JavaScript by the webpage. When you open the url in the Chrome, the JavaScript code is executed by the browser, which generates the drop-down-menu with the keyboard options.
You should check out a headless-browser (PhantomJS etc.) which will do the JavaScript execution. With Splash, Scrapy offers its own headless-browser which can be easily integrated via scrapyjs.SplashMiddleware Downloader Middleware.
https://github.com/scrapy-plugins/scrapy-splash
The cause that //select/option does not find anything is that there is no select tag in the website when you load it with scrapy. That's because JavaScript is not executed and the dropdown is not filled with values.
Try to disable javascript from your Chrome developer tools' settings and you should see the same empty website what scrapy sees when you scrape the page.

Dropdown menu does not trigger in oneui 3.0.2 (in Firefox)

I use an dropDownButton from the extlib, which does not work when I changed to OneUI 3.0.2 (from 2.1, in which it works fine).
Happens in firefox (31.8), not in (a very old) IE. Firebug shows the following error in its console, when I click on on of the dropdown entries:
TypeError: _9.getAttribute is not a function ,
and it point to ...{return _6[_9.getAttribute("widgetId")];}... in the lib -extlib.dijit.OneUIv302Dialog&-extlib.dijit.OneUIv302Menu&#Eya.js
Is it a (known) bug?
my code:
<xe:dropDownButton
id="dropDownButton1">
<xe:this.treeNodes>
<xe:basicContainerNode
label="IAM">
<xe:this.children>
<xe:basicLeafNode
submitValue="approve1" label="approve selected">
</xe:basicLeafNode>
<xe:basicLeafNode
submitValue="reject0" label="reject selected">
</xe:basicLeafNode>
</xe:this.children>
</xe:basicContainerNode>
</xe:this.treeNodes>
<xp:eventHandler
event="onItemClick" submit="true"
refreshMode="complete">
<xe:this.action><![CDATA[#{javascript:submitIAMAction()}]]></xe:this.action>
</xp:eventHandler>
</xe:dropDownButton>
I have tested the Extension Library DropDownButton in conjunction with OneUI V3.0.2 without any troubles.
UPDATE "Output on server console":
I am working with the following environment:
Firefox 42
Domino Server 9.0.1FP4
Extension Library Version 9.0.1.v00_14_20150831-1301
It could be a problem with your Domino Server and/or Extension Library Version?
Try to do some updates on your environment.
It sounds like the same issue we had. In our case, I think the drop down entries could still work if you clicked on the actual text in the drop down option, clicking in the 'white space' would not work.
We found a solution thanks to Serdar Basegmez in the Defect list in ExtLib project on OpenNTF
http://extlib.openntf.org/main.nsf/project.xsp?r=project/XPages%20Extension%20Library/defects/0FFE08B1FC57FE6A86257D91004C156D
Give this a try:
put the following in a javascript library.
if(dojo.isMozilla) dojo.addOnLoad(function() {
dijit.registry.backupByNode=dijit.registry.byNode;
dijit.registry.byNode=function(node) {
if(node.getAttribute) {
return dijit.registry.backupByNode(node);
} else {
return dijit.registry.backupByNode(node.parentNode);
}
}
});
and then add your theme: (add add as a resource to a single page)
<resources>
<script src="/fixDropDownButton.js" clientSide="true"
type="text/javascript"></script>
</resources>

Installing an editor plugin in web2py app

I am trying to install an editor plugin "ck-editor4" in my web2py app, following the steps at:
http://www.web2pyslices.com/slice/show/1952/ck-editor4-plugin
and
https://bitbucket.org/PhreeStyle/web2py_ckeditor/wiki/Home
I wrote the given piece of code in my application's "model/db1.y" and "views/default/index.html" as directed in the above links, but things are not working correct. I am a newbie in web2py. Please help me installing an editor (preferably which supports programming languages) in detailed steps. Thanks!
This worked for me:
in db.py:
from plugin_ckeditor import CKEditor
ckeditor = CKEditor(db)
db.define_table('wpage',
Field('title'),
Field('body', 'text',widget=ckeditor.widget),
auth.signature, # created_on, created_by, modified_on, modified_by, is_active
format='%(title)s')
In default.py:
#
auth.requires_login()
def create():
"""creates a new empty wiki page"""
ckeditor.define_tables()
form = SQLFORM(db.wpage).process(next=URL('index'))
return dict(form=form)
I used ckeditor.define_tables() in edit() and show() too. Now in show.html, display the formatting using:
{{=XML(page.body,sanitize=False)}}
This is all explained in the links in your post and
https://github.com/timrichardson/web2py_ckeditor4
By the way, I found a simple way to install an editor for web2py app. This is not ck-editor4 plugin but NicEdit. Just two lines of javascript code will do the job. Following link came as rescue to me.
http://nicedit.com/
Just follow the simple steps in "Quick Start Guide" right hand side. Create a textarea and your work is done.

Not Able to Take Screenshot on Safari using Grid and RemoteWebDriver

I am trying to get a screenshot from Safari using Grid and RemoteWebDriver. I have tried the following approaches:
Using the code below. It works on all browsers except Safari. I also tried returning a BASE64 string but didn't work.
WebDriver augmentedDriver = new Augmenter().augment(driver);
File source = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(source, new File("screenshot.png"));
Exception: org.openqa.selenium.WebDriverException
Using WebDriverBackedSelenium. This throws exception.
a.
Selenium sel = new WebDriverBackedSelenium(driver, driver.getCurrentUrl());
sel.captureScreenshot(filename);
Exception: java.lang.UnsupportedOperationException: captureScreenshot
b.
Selenium sel = new WebDriverBackedSelenium(driver, driver.getCurrentUrl());
sel.captureScreenshotToString();
Exception: java.lang.UnsupportedOperationException: WebDriver does not implement TakeScreenshot
I tried sending the key sequence that takes screen shots in MAC (command+shift+3) using sendKeys(Keys.chord(Keys.COMMAND, Keys.SHIFT, "3")) but Keys.COMMAND is not considered as modifier key so this also didn't work.
After some research I came across the issue below:
http://code.google.com/p/selenium/issues/detail?id=4203
I also saw this revision which is suppose to fix the issue but I am not able to figure out how to implement this
http://code.google.com/p/selenium/source/detail?r=17731
I would really appreciate if I could get some help on this. I am using MAC, Safari 5.1.7 and selenium 2.25.
For future reference: this seems to have been fixed in Selenium 2.26

Resources