Click element with selenium2library - webdriver

My whole test suite is based on robotframework with the SeleniumLibrary (RC). I'm trying to port it to Selenium2 (webdriver). I'm facing an issue with the Click Element keyword which does not support coordinates argument anymore. I read this post which mentions a MoveToOffsetAction but cannot find it whithin the Selenium2Library seen from robotframework.
I also read that the webdriver API has a click_at(locator, coordString)
To sum up the situation, I'm wondering how to convert my selenium RC Click Element Locator Coordinates to a Selenium2 keyword or set of keywords.
Thanks a lot for your help,
Pierre

In Selenium2 API there is no option to click the element using the co-ordinates.
But you can resolve the issue by using the Action class.
Try this code:
//Assume driver is instantiated somewhere properly.
WebElement ele = driver.findElement(By.xpath(Element locator));
Actions builder = new Actions(driver);
builder.moveToElement(ele, 100, 200).click().perform();
By using the above code you can move to the particular element using co-ordinates(here button) and able to click.
For more info http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/interactions/Actions.html

Related

How to do Doubleclick Element on SAP GUIShell using Robot Framework?

I am trying to automate my work in SAP using the Robot Framework with the SapGuiLibrary, but at the moment I’m having difficulties executing the Doubleclick Element command on a shell object.
After inspecting the object with Script Tracker I found the lines below:
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").setCurrentCell 2,"STRAS"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectedRows = "2"
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").doubleClickCurrentCell
The command asks for 3 parameters:
Doubleclick Element element_id item_id column_id
So I put like this:
Doubleclick Element wnd[0]/usr/cntlGRID1/shellcont/shell 2 STRAS
But it dind't work as you can see below:
AttributeError: <unknown>.doubleClickItem
So what am I doing wrong?
I think it's a current limitation of SapGuiLibrary.
The keyword DoubleClick Element is only for double clicking an item in a Tree control of type "List" or "Column" (object GuiTree).
In your case, you want to double-click a cell in a Grid control (object GuiGridView), but SapGuiLibrary doesn't propose a keyword for that.
Either you file a bug at https://github.com/frankvanderkuur/robotframework-sapguilibrary/issues, or you do the correction yourself.
NB: if you're a developer, you may see all the limitations by comparing the SapGuiLibrary code and all possible SAP GUI Scripting objects and methods (use this direct link if the search hangs).

How to check if imageview resource is right when using robot framework + Appiumlibrary mobile testing

I have simple Android app and I try to test it with Robot Framework and appiumlibrary combo. I struggle with the imageview checks. I have one imageview and image changes based on the values ​​calculated. Can I check is the image right (expected)? For example, if the calculated result is 30, the image should be ylip.jpg. How can I check that the resource/ image is correct? I have tried many ways and test don't run or I get valuerrors.
from Robot code:
Element Should Be Visible imageView2 //* [#id="imageView2"]/image[contains(#drawable, "norm.jpg")]
From layout:
android:id="#+id/imageView2"
From activity:
else if (result >18.5 && result <=30){
image.setImageResource(R.drawable.ylip);}
To me I think UI Element inspector can't know the image resource name. If you really want to compare image there is one library call RobotEyes you can use it to compare the image. Second solution is you have to dynamic your resource-id name in application to match your condition.
RobotEyes

How do I send data to this checkbox using python with selenium web-driver

I am trying to automate this webpage and send some data to a checkbox with a dynamic #id.
I have used sample codes I found online but the test keeps failing due to not finding the element.
XPath for the webpage text box: //*[#id="undefined-Filter-undefined-24212"]
element:
In the snipped provided, the 24212 int is dymanic.
You can try something like and instead of name use x_path:
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
For reference : https://selenium-python.readthedocs.io/getting-started.html

Click element, hold Shift key and click another element in robotframework

I need to be able to click an element on a webpage and hold the Shift key on keyboard and press another element.
Can I implement this behaviour using "Press Key" in Selenium2Library?
You can try to achieve your scenario using AutoItLibrary
First you need to install win32com.client, use below command
pip install pypiwin32
Then use AutoItLibrary command like as per your requirement
Send | {SHIFTDOWN}
For more info visit here
Use using Pyautogui library. This library simulates the User Actions on GUI such as Mouse Control, Keyboards inputs,etc. You can find details at
https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwjN1ZbrocrSAhWIFJQKHXbiBGcQFggbMAA&url=https%3A%2F%2Fpyautogui.readthedocs.io%2F&usg=AFQjCNEe5LY5eMdaquVD421_u-mpoFUOYQ&sig2=Lj-e4YldvbLNEvPe4NFHrA
Also U can install this library using pip by following keywords in following docs
http://pyautogui.readthedocs.io/en/latest/install.html

How can I make Selenium interact with a file input field with an opacity of 0?

In the project I'm working on, we have a lot of file input fields with an opacity of 0.
if I have an input field wih an id of file_upload and opacity:0,
then #driver.find_element(id: 'file-upload').send_keys full_file_path will give me a Selenium::WebDriver::Error::ElementNotVisibleError
How can I successfully attach a file to this input?
Im am using selenium-webdriver for Ruby
Note:
I know that this is possible to do with Capybara but using Capybara is not currently an option in my project.
One option is to it with execute_script instead of find_element.send_keys:
full_file_path = "./path/'
script = <<-JS
document.getElementById("#file-upload").val("#{full_file_path}")
JS
#driver.execute_script script
The Java code, which is working fine.
WebDriver driver = new ChromeDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.querySelector(\"input[id*='upload']\").style.opacity='1'");
driver.findElement(By.cssSelector("input[id*='upload']")).sendkeys(filepath);

Resources