Please help solve this issue. I have chart written using devexpress.
http://image.ibb.co/hRD5oR/chart.png
And I have such test on Selenium. It opens a page with chart and clicks all elements (minimize/maximize, expand/collapse). Here is code:
driver.findElement(By.xpath("/html/body/form/div[3]/div[2]/div[1]/div[1]/div/div[1]")).click();
Thread.sleep(1000);
driver.findElement(By.xpath("/html/body/form/div[3]/div[2]/div[1]/div[1]/div/div[1]")).click();
Thread.sleep(1000);
// Switch to a new window / Get the handle
String parentHandle = driver.getWindowHandle();
System.out.println("Before click Category 1");
// Click bar to open drilldown
//FSMSDashbopadObjects.NCbyReportCategoryBarCategory1(driver).click();
driver.findElement(By.xpath("/html/body/form/div[3]/div[2]/div[1]/div[2]/div/svg/g[8]/g/g/rect[1]")).click();
//*[#id="auditsByBrandDiversey"]/svg/g[8]/g/g/rect[1]
System.out.println("After click Category 1");
The test has failed on this step:
driver.findElement(By.xpath("/html/body/form/div[3]/div[2]/div[1]/div[2]/div/svg/g[8]/g/g/rect[1]")).click();
Selenium can't locate this bar. I suppose that there are some nuances with svg.
Please advice how to resolve it.
I am going to answer your question, but there are multiple solutions for this.
Now, if you always have 5 bars, your problem is quite easily solved.
In case of 5 bars, and always 5 bars on your entire page:
This is going to return 5 elements:
driver.FindElement(By.XPath("//g[#class='dxc-markers']/rect");
To be sure, hit F12 in chrome, click on Console, typ: $x("//g[#class='dxc-markers']/rect")
Now if you are getting 5 elements back, use:
driver.FindElement(By.XPath("(//g[#class='dxc-markers']/rect)[1]");
driver.FindElement(By.XPath("(//g[#class='dxc-markers']/rect)[2]");
driver.FindElement(By.XPath("(//g[#class='dxc-markers']/rect)[3]");
driver.FindElement(By.XPath("(//g[#class='dxc-markers']/rect)[4]");
driver.FindElement(By.XPath("(//g[#class='dxc-markers']/rect)[5]");
Now if the amount of bars is variable, you need to create an array of the elements you get back. Once you have the array, instead of the [1] insert the array value there and you are set.
Related
ok so I cannot share the website I'm trying to automate but I'll share a screen shots of the inspect view.
ill add the code i used and the log i got from it
as you can see the class: data-command has three elements within in the number is dynamic but I need to click on the last one, i do not want to use absolut xpath as the class: data-command is dynamic.
ill add the code i used and the log i got from it
how do i click the last element
##{element_value}= Get WebElements class:data-value
#{elements_name}= Get WebElements class:data-label
#{element_commands}= Get WebElements class:data-command
WHILE ${i} < 5
#Log To Console ${element_commands[${i}]}
Click Element ${element_commands[${i}]}
Sleep 5s
#Capture Page Screenshot
Run Keyword And Warn On Failure Page Should Contain ${graph}
${i}= Evaluate ${i} + ${one}
END
I'm not familiar with robot framework, but is case data-command class is a unique locator, the following XPath will give you the last child inside that element:
"(//div[#class='data-command']//*)[last()]"
You can get elements store it in collection/list and then get the last one and click it:
List<WebElement> elements= driver.findElements(By.css(".data-command"));
element = elements.get(list.size() - 1); //Click only the last in the list
I am having a really hard time understanding the following problem, i have an app, i use appium inspector to see the elements, but when i use the elements, i get that the element is not found, therefore i printed the code using the driver.getPageSource() method, and i realized that the xml code that is created while running the app, is actually different to what appium inspector sees, what is the problem and how can it be solved? i could ask to the developers to fix it once i know the root cause, thanks in advance.
This is an example of a difference
Under < XCUIElementTypeOther name = Picture, Left Rear Corner> there are 4 more elements 2 StaticText, 2 Buttons (appium inspector) and on the the same element but in the java console, there are only 2 tags, so i do not see the 2 static text and the 2 buttons (which is what i want to click)
As you can see the code in the console is different to what i see in appium iinspector. this is for IOS app.
while (driver.findElementsById("Additional Videos").size() == 0) {
swipeScreenDown();
}
driver.getPageSource();
WebElement additionalVideos = driver.findElementByXPath("//XCUIElementTypeOther[#name=\"Picture, Left Front Corner\"]");
driver.getPageSource();
List<WebElement> idf = additionalVideos.findElements(By.className("XCUIElementTypeButton"));
driver.getPageSource();
System.out.println(idf.size());
driver.getPageSource();
idf.get(0).click();
driver.getPageSource();
Error got:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
PageSource() action can print the visual elements at the screen.
As per my understanding, You are currently performing PageSource() action when loading the screen.
You need to click at the selected element
After click on this element use PageSource() action.
You get that element in the log of the PageSource().
I am clicking with the help of following lione oc code->
actions.moveToElement(objDriver.findElement(By.id("id_popcode")),coordinates.getX(),coordinates1.getY()-1).doubleClick().build().perform();
Basically i double click at a position(x,y) in our application. Individually we cannot click that particular element bcoz it has to be clicked at particular (x,y) itself. So i want to get the properties of that clicked element(which i click using actions command which i mentioned above) liked id, classname. Can some one help me with this...kinda stuck here..........
edit:
try execute.elementFromPoint() with JavascriptExecutor to get element by coordinates
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement theElement = (WebElement)js.executeScript("return document.elementFromPoint(arguments[0], arguments[1])", coordinates.getX(), coordinates1.getY()-1);
System.out.println(theElement.getAttribute("tagName"));
System.out.println(theElement.getAttribute("class"));
old:
you are using negative value in getY()-1 which mean coordinates above the element, it maybe the parent or preceding-sibling of element try to select it using xpath
WebElement popcodeBefore = objDriver.findElement(By.xpath("//*[#id='id_popcode']/parent::*"));
// Or
// WebElement popcodeBefore = objDriver.findElement(By.xpath("//*[#id='id_popcode']/preceding-sibling::*"));
System.out.println(popcodeBefore.getAttribute("class"));
actions.moveToElement(popcodeBefore).doubleClick().build().perform();
If you have any specific text at that particular coordinates make use of it. I too had the same issue like this where I need to double click on a cell which had text 0.00%. I have done hovering action first using the text and then performed the double-click
Ignore the syntax issues since I am working on the protractor these days
browser.driver.actions().mouseMove(driver.findElement(by.xpath("//*[text()='00')]").build().perform();
and then perform the click
Still, you have issues, check if you have any attribute like ng-click which can be helpful to get the coordinates for that particular location. please always share the HTML code so that It may help us to check more deeply
In our application when I mouse over a menu item, drop down appears, where I want to select an item by clicking on it. The structure of the menu is as follows,
Main Menu
Admin Sub menu:
Manage Channels
Manage Users
In selenium webdriver, I tried to click directly on Manage Channels by giving the xpath, linktext, partial link text. But in options it says unable to locate element. I'm attaching a screen shot for reference
driver.findElement(By.linkText("Manage Channels")).click();
driver.findElement(By.xpath("//li/a[contains(., \"Manage Channels\")]")).click();
driver.findElement(By.partialLinkText("Manage Channels"));
Basically, you'll have to first move mouse to 'Menu item' drop-down and then move mouse to option which you want to select and then click on option.
For Ruby following is one line code:
driver.action.movet_to(el1).movet_to(el2).click.perform
I don't know about Java but you can apply above logic. I tried with following Java code, see if it works or modify it wherever required:
WebElement element1 = driver.findElement(By.linkText("Manage Channels"));
WebElement element2 = driver.findElement(By.xpath("//li/a[contains(., \"Manage Channels\")]"))
Actions action = new Actions(driver);
action.moveToElement(element1).moveToElement(element2).click().build().perform();
You can use following methods to hover your mouse on intended menu item:
el = driver.find_element(:id, "some_id")
driver.action.move_to(el).perform'
el = driver.find_element(:id, "some_id")
driver.action.move_to(el, 100, 100).perform
For more guidelines please refer this link : http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html#move_to-instance_method
Hope this will help you !!!
Cheers...
I have 5 tooltips in page. Using WebDriver, I am trying to verify these tooltip text.
I am using following code sequentially to get the tooltip text of all 5 elements:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
The issue is I get only the tooltip text of first element printed in console.
Is it because I need to refresh or reset the builder?
It's really weird when I delete the code for 1st element , then I can get tooltip text of 2nd element. So, basically it is getting tooltip text only once in single execution.
Verify tool tip by comparing "title" attribute of the web element and your expected tool tip text.
Console.WriteLine(Element1.GetAttribute("title"));
Console.WriteLine(Element2.GetAttribute("title"));
Tool tip text for input elements would be the title attributes and for images, alt attribute would be the tool tip.This is the standard for HTML 4, so I am not sure if you need to do hover and all.
Console.WriteLine(InputElement1.GetAttribute("title"));
Console.WriteLine(ImageElement1.GetAttribute("alt"));
http://www.javascriptkit.com/howto/toolmsg.shtml
I think, it needs to release from element as:
builder.release(Element1).perform();
So, your code could be as below:
Actions builder = new Actions(WebDriver);
builder.ClickAndHold(Element1).Perform();
Console.WriteLine(Element1ToolTip.text);
builder.release(Element1).perform();
builder.ClickAndHold(Element2).Perform();
Console.WriteLine(Element2ToolTip.text);
builder.release(Element2).perform();
builder.ClickAndHold(Element3).Perform();
Console.WriteLine(Element3ToolTip.text);
builder.release(Element3).perform();
I am facing the same issue , i checked the view source page on running the test and it appears that the title attribute is displayed as data-original-title.Due to which it is unable to display the text.On replacing the title with data-original-title . I am able to obtain text.