Script in UI
<div class=navdeactive>Technology</div>
While executing the below script
#driver.find_element(:link_text, "Technology").click
Getting an error>>
Selenium::WebDriver::Error::NoSuchElementError: The element could not
be found
But in view, source link is available.
Web Driver version: selenium-webdriver (2.25.0)
Help me on this
Based on your question you can use xpath and click the particular Html locator.
i have been given below script using python web driver. try this one.
driver.find_element_by_xpath("//a[text()='Technology']").click()
Answer:
In UI text is displayed as TECHNOLOGY But in the Page View Source text is displayed as Technology I have changed the code as #driver.find_element(:link_text, "TECHNOLOGY").click...... Now its worked fine...
Related
I have been using Selenium to test the user interface of my AEM site on preview mode. It was done without any technical problem. However, when I try to run selenium test on editor or author mode, such as clicking on a web component to open component dialog, my webdriver is unable to get the web element and throw an exception calledĀ org.openqa.selenium.elementnotinteractableexception.
I have tried to solution on StackOverflow, but none of the solution is helpful for what I am doing.
For example, I have something like this on selenium in Java:
WebElement button =
driver.findElement(
By.cssSelector(
"div[data-path='/content/components-examples/library/button/jcr:content/root/responsivegrid/test/component/button']"));
button.click();
The element Not interactable exception is thrown once I try to click on it by using "button.click()".
However, if I do the same thing on Preview mode, nothing will happen but the button getting clicked, and no exception will be thrown.
Does AEM support selenium automatic testing on editor or author mode? If it does, how can I overcome this issue?
I wont suggest doing automation testing on AEM author because the components will keep on changing and it will be very difficult to get a particular selector.
For example if you are selecting the button using the cssSelector with data-path, what if the button is changed, few more buttons are added before the particular button you are targeting.
About supporting selenium, I am not sure but for unit testing mockito is mostly used. Hope this helps.
My application works in Internet Explorer and I want to write xpath to create selenium test suite.Please suggest how to write and execute xpath in IE browser.
You can install Firebug which is an Add-on for Firefox. Firebug integrates with Firefox to put a wealth of web development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page.
You can also generate Xpath and use it in your code.
It is unclear what you want to achieve. XPath over downloaded HTML text, XPath over generated DOM in browser page, XPath over some XML taken either from XML island in browser page or from external source...
If you need to evaluate XPath on existing page this page should be treated as XHTML or XML document by IE. I.e. not any page has native support for XPath.
If the page is not xmlDocument you could read page dom and create clone XML.
Once you have XML then simplest is to use libs like xml4jquery or AmdHarness-amd-xml and evaluate XPath in JavaScript.
If you need to run XPath on someone else's page the easiest way is to run JS by bookmarklet. Something like http://xmlaspect.org/XmlView . The bookmarklet gives the JS string as a function body to be run by Selenuim code.
LMN if the bookmarklet is the solution you are looking for, I will create one for XPath.
The selenium web driver allows to run script as well:
String title = (String)jse.executeScript(
"return document.evaluate(xPath, node, null, 9, null).singleNodeValue");
But you still need the XML source and code for extracting the XPath results as string, array, NodeList where JS libraries at your service.
I am getting Cannot locate an element using By.xpath error in Selenium using Java(IE11). I am working on a web page created using Adobe AEM(CQ5).
I have tried the following possible solutions but neither of it helped.
Tried to add wait.
Switch to active window.
Tried even on Chrome.
Bring focus on element.
Currently using the absolute path (/html/body/div[4]/header[1]/div[1]/div[2]/div[5]/div[1]/nav/ul[1]/li[3]/a) but also used relative path (.//*[#id='cq-gen188']/nav/ul/li[3]/a).
Also searched whether there is any iframe involved. Unfortunately there was none.
To find the xpath, I have used FirePath plugin in Firefox. When i search for the element using the xpath in Firefox, i am successful. But when i execute the code i get the error.
If you are in the correct IFRAME then you can use
driver.findElement(By.id("cq-gen188"));
Remember that ID is always unique and that's a core assumption for all of the libraries in the authoring UI whether it is from core AEM framework or from custom components.
Your problem may be due to incorrect IFRAME as AEM neatly makes the UI look like a seamless window but there are IFRAME in place to facilitate various authoring navigation experiences.
I am having handling a drop down button in EXTJS application which i am trying to automation with selenium web driver.
clicking on the image i will get a list of elements in the form of 's
to click select from
Please help me how i can device a xpath to click this image, which i should not use "id" (as its extjs it might vary every now and then).
if there are any selector i can use for extjs please suggest. Thanks for your help.
<DIV id=ext-gen2337 class=x-form-field-wrap style="WIDTH: 0px"><INPUT id=ext-gen2023 class=" x-form-text x-form-field" style="WIDTH: 297px" readOnly size=24 value="Clients with pending exceptions" name=ext-gen2023 autocomplete="off"><IMG id=ext-gen2338 class="x-form-trigger x-form-arrow-trigger" src="https:REDACTED/com.ssc.epw.gui.EPWHome/clear.cache.gif">
Try below XPath to match required img element:
//input[#value="Clients with pending exceptions"]/following-sibling::img
So if you want to start testing ExtJS app and you don't want to use the best solution for this such as Sencha Test or Bryntum Siesta.
The best way to approach this is to write you own layer between the ExtJS components and the html dom of the site.
You can see more info in my answer here https://stackoverflow.com/a/41718879/1768843
But what you need to do is to use the Ext.Component.Query, with Selenium you can execute the javascript code on the site. So you execute the ext query and you pass there the Ext selector - for example button[text=something] or panel[name=mainPanel] simply any ExtJS component selector. This will return you the ExtJS object and with it you can simply call .getDom() or .getId() which will return you the actual dom or id used in the HTML. Next you can simply use the webdriver functions for clicking (or something) on the HTML elements in the site.
^^ You need to do this because the ExtJS framework can generate the HTML every-time little bit differently. For example you add new container or you upgrade your ExtJS version and the HTML is changed and your test can stop working. But if you call the Ext components as log as the Ext source code is still the same your tests will be always working.
But doing this is quite a hassle and lot of work. It's much better to use prepared solutions such as Sencha Test where everything is already prepare for testing ExtJS apps.
I would do something like this:
driver.findElement(By.xpath("//div[contains(#class, 'x-form-field-wrap')]//img"));
or
driver.findElement(By.xpath("//img[contains(#src, 'https://REDACTED/com.ssc.epw.gui.EPWHome/clear.cache.gif')]"));
After exhaustively searching for this over various forums, I still don't have an answer.
Here are complete details
I'm identifying the element through classname which points to multiple(4) buttons. I'm iterating through buttons and then search for text and when there is a match i click it.
This works fine with selenium webdriver and browsers such as firefox,chrome
Now I'm doing the same thing with appium.
Out of 4 buttons which are identified through classname, the script clicks 2 buttons successfully but for two buttons click happens(i can see the button being clicked) but new page which should be loaded is not loaded. The buttons for which click is not happening are in a footer class and other two are in div class.
Things i have already tried
Actions builder - click(), clickandhold()
Javascript executor
I'm currently trying with touch options, tap and by switching to native view but haven't found any success.
If any has encountered the same, a solution will be appreciated.
I want to avoid xPath because that might change in the page I'm working on, and I want to stress that the script is able to find the button, but is not able to click it properly.
You can filter your locator by using class name and index. Like this:
driver.findElementsByXPath("//*[#class='android.widget.ImageView' and #index='0']");
This xpath won't get change on other devices too.
Could you see: Unable to find an element in Browser of the Android emulator using Appium and C# ?
In case of testing web apps in browser the elements should be located as usual elements on the web page ( not as some classes like android.widget.EditText and android.widget.Button).
Upadting appium java client to 1.5.0 (from 1.3.0) solved the issue. Need to check why!