How to use resource id in Appium - selenium

I am testing a mobile app which doesn't have right set locators in it, so i can use only "resource-id"
from appium.webdriver.common.appiumby import AppiumBy
# Locators
profile_btn = (AppiumBy.ID, 'io.dzain.dzain.uat:id/navItemIV')
profile_btn.click()
When I run this code following error message is displayed
AttributeError: 'tuple' object has no attribute 'click'
How can i use the resource-id to handle this problem?

You call clicks on the appium/webdriver elements returned from the driver, something like so:
profile_btn = self.driver.find_element(AppiumBy.ID, 'io.dzain.dzain.uat:id/navItemIV')
profile_btn.click()
You feed your by method and your element locator definition into the find_element function and call clicks on the element object it returns to you.

Related

javascript error: Right-hand side of 'instanceof' is not an object error using expected_conditions with Selenium Python

I have some code in selenium/python, which used to work, But now I'm getting:
javascript error: Right-hand side of 'instanceof' is not an object
I don't know if it's something that was changed in the angular application, or how this error is relevant to what I'm doing.
I get it after trying to locate a webelement or waiting for visibility of element, like:
wait.until(expected_conditions.visibility_of_element_located(leftNav_page.pageSmallTitle))
"pageSmallTitle" is just a locator like:
pageSmallTitle = (By.CSS_SELECTOR, "span[id$='componentTitle']")
Tried changing it to xpath, but didn't make a difference.
I would highly appreciate any suggestion!
visibility_of_element_located() accepts a locator as an argument and the expression is as follows:
wait.until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, "span[id$='componentTitle']")))
In your usecase, if:
pageSmallTitle = (By.CSS_SELECTOR, "span[id$='componentTitle']")
the effective line of code must have been:
from selenium.webdriver.support import expected_conditions
wait.until(expected_conditions.visibility_of_element_located(pageSmallTitle))
so essentially there is an additional parameter as leftNav_page. Hence you see the error.
Removing the extra parameter will solve the issue.

How to resolve "Using 'Get Element Attribute' without explicit attribute is deprecated" in robot framework using selenium library

This works and returns exactly what I want:
*** Variables ***
${HOME_LOGO}= css=#header > nav > div.header-gutter > div > img
*** Keywords ***
Home logo is visible
Element Should Be Visible ${HOME_LOGO}
${logo_src}= Get Element Attribute ${HOME_LOGO}#src
log ${logo_src}
However, I am getting a WARN when I run it: Using 'Get Element Attribute' without explicit attribute is deprecated
I have tried several approaches, but have not been able to resolve the warn message AND get the information I want into ${logo_src}. I am looking for the img src.
What is the best way to either handle the warn or get the img src from the element in the xpath?
Thank you - I'm very new to robot framework and selenium but not new to test automation. Also new to stackoverflow.
They have changed how this keyword works from when it was originally designed. Instead of appending the attribute to the locator, provide it as an argument:
${logo_src}= Get Element Attribute ${HOME_LOGO} src
(note: there needs to be two or more spaces before src)

How do i scroll down to an element in Katalon?

I am unable to scroll down to the save button at the end of the page. Have tried using scrollToElement function but it does not work.
The error given :
Test Cases/merchantAdd1 FAILED because (of) groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.scrollToElement() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject)
This doesn't necessarily mean you are unable to scroll to an element. You are missing a parameter.
The error message is saying you are trying to pass the wrong types of argument to scrollToElement() function. It is expecting a TestObject and an int (timeout in seconds) and you are passing in only the test object.
It should be something like
WebUI.scrollToElement(findTestObject('your test object'), 3)
If you are unable to find Test Object, and it is at the bottom of the page, try scrolling to position high absisse and ordinate.
for example WebUI.scrollToPosition(9999999, 9999999)
Then try click on the Objct

Robot Framework: How to make Wait until keyword from selenium library return true or false

I would like to Run a keyword if an element is present on page.
I try using Selenium library's Wait Until Page Contains Element keyword, but it will always return "None", whether or not the element is present. I tried setting custom error, but that won't work either:
${condition} = Wait Until Page Contains Element ${locator} timeout=5 error=false
Run Keyword if '${condition}'=='false' click element ${some_refreshButton_locator}
Keyword click element ${locator} will run only when I make condition '${condition}'=='None'
Am I doing something wrong and how can I make a Selenium Library Wait until... keyword return true or false.
Thanks!
Wait Until Page Contains Element does not return anything but will raise error if element is not found. One workaround is to wrap Run Keyword And Ignore Error around it.
*** Settings ***
Library Selenium2Library
*** Test Cases ***
Test wait
Open Browser http://www.google.com/ gc
${result} ${condition}= Run Keyword And Ignore Error Wait Until Page Contains Stackoverflow timeout=2 error=false
Run Keyword if '${condition}'=='false' Log clicking
Close All Browsers
"Run Keyword And Return Status" can also be used to get True/False status as below:
${condition} = Run keyword And Return Status Wait Until Page Contains Element ${locator} timeout=5 error=false

Couldn't get the uid in Odoo JavaScript

I'm trying to learn JavaScript for Odoo. I've created a new class in my custom module's js file.
openerp.odoojs = function(instance){
console.log('instance: ',instance);
console.log('session: ',instance.session);
}
This is what I'm getting when I browse the session object in the console.
But when I try to access the uid or any other attribute or parameter like instance.session.uid, I'm getting it as undefined. Please help! I'm stuck with this. I'm unable proceed further.
Try to extend the 'Backbone.Model' like 'PosModel' in 'model.js' file. Try to define the 'initialize' function, where you will find two parameters in function arguments as 'session' and 'attributes'. Here you can find the uid using 'session.uid'.