I trying to click on a button with UiAutomator, but receive error "androidx.test.uiautomator.UiObjectNotFoundException"
I tried to locate object in two ways.
UiObject cartButton = uiDevice.findObject(new Selector().resourceId("R.id.group_cart_add_button"));
UiObject2 cartButton = uiDevice.findObject(By.res(InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName(), "R.id.group_cart_add_button"));
Then I use cartButton.click() but both times I receive an error.
In hierarchy this object is exist
And when I try to find it in Evaluate tool, I can do it:
But if I try to click, I receive an error:
Why?
You can do the following:
String packageName = "your-app-package-name"
String fullCartButtonResourceId = packageName + ":id/group_cart_add_button";
UiObject2 cartButton = mDevice.findObject(By.res(uk));
or
UiObject cartButton = findObject(new UiObject(new UiSelector().resourceId(fullCartButtonResourceId));
Related
// but the code is throwing unexpected terminal operator new
function MovePokemon(argument0, argument1) {
old = argument0;
new = argument1;
TPartyID = global.PartyID[old]
global.PartyID[old] = global.PartyID[new]
global.PartyID[new] = TPartyID;
new is a keyword in the current versions of GameMaker, so you'll need to rename that variable (say, to _new).
The project in question may leave some to be desired given the complete absence of local variable declarations (var).
Try use this code in your script to avoid use "new"
function MovePokemon(argument0, argument1) {
TPartyID = global.PartyID[argument0]
global.PartyID[argument0] = global.PartyID[argument1]
global.PartyID[argument1] = TPartyID;
I want iterate over a list of string, output the string as plain text in jupyter lab then interactively highlight a substring to get easily the start index of the substring and the length. The goal is to do a quick annotation of text and get the coordinates of the substring.
Is it easy or even possible to do something like this with jupyter notebook (lab)? If then How?
I had a look at ipywidgets but couldn't find something for this use case.
Here's an example with the RangeSlider:
import ipywidgets
input_string = 'averylongstring'
widg = ipywidgets.IntRangeSlider(
value = [0, len(input_string)],
min=0, max=len(input_string)
)
output_widg = ipywidgets.Text()
display(widg)
display(output_widg)
def chomp_string(widg):
start,end = tuple(widg['new'])
output_widg.value = input_string[start: end]
widg.observe(chomp_string, names='value')
You can implement this using jp_proxy_widgets. See the following screenshot:
Note that there are warnings about compatibility for selection protocols -- I only tested this on Chrome on a Mac. Also I don't know why the indices are off by one
(select_callback(startOffset+1, endOffset+1);)
Please see https://github.com/AaronWatters/jp_proxy_widget for more information
Edit: Here is the pastable text as requested:
import jp_proxy_widget
select_widget = jp_proxy_widget.JSProxyWidget()
txt = """
Never gonna give you up.
Never gonna let you down.
Never gonna run around and
desert you.
"""
selected_text = None
def select_callback(startOffset, endOffset):
global selected_text
selected_text = txt[startOffset: endOffset]
print ("Selected", startOffset, endOffset, repr(selected_text))
select_widget.js_init("""
// (Javascript) Add a text area.
element.empty()
$("<h3>please select text:</h3>").appendTo(element);
var textarea = $('<textarea cols="50" rows="5">' + txt + "</textarea>").appendTo(element);
// Attach a select handler that calls back to select_callback.
var select_handler = function(event) {;
var target = event.target;
var startOffset = target.selectionStart;
var endOffset = target.selectionEnd;
select_callback(startOffset+1, endOffset+1);
};
textarea[0].addEventListener('select', select_handler);
""", txt=txt, select_callback=select_callback)
# display the widget
select_widget.debugging_display()
Here is the window I need to enter new password and repeat it again and click 'create'.
My code so far:
createLogin = wait.until(EC.presence_of_element_located((By.XPATH, '//*[#id="Item.MessageUniqueBody"]/div/div/div/div/div[2]/div[2]/a')))
createLogin.click()
time.sleep(10)
try:
newPassword = self.driver.find_elements_by_xpath('//*[#id="editNewUser_newPassword"]')
newPassword1 = self.driver.find_elements_by_xpath('//*[#id="editNewUser_newPasswordRepeat"]')
newPasswordForm = self.driver.find_elements_by_xpath('//*[#id="editNewUserPasswordForm"]/table/tbody/tr[1]/td[1]')
self.driver.switch_to.active_element(newPasswordForm)
time.sleep(3)
newPassword.send_keys('123')
newPassword1.send_keys('123')
time.sleep(2)
# createLog = wait.until(
# EC.presence_of_element_located((By.XPATH, '//*[#id="editNewUserPassword_save"]')))
# createLog.click()
# time.sleep(5)
except NoAlertPresentException as e:
time.sleep(2)
myAccount = wait.until(
EC.presence_of_element_located((By.XPATH, '//*[#id="easMyAccount1"]')))
myAccount.click()
time.sleep(5)
This is the problem.
You are using find_elements_by_xpath rather than find_element_by_xpath
plural vs singular.
find_elements_by_xpath: it gives you a list of web elements with matching identifier.
find_element_by_xpath: it gives you a first web element with matching identifier.
newPassword = self.driver.find_element_by_xpath('//*[#id="editNewUser_newPassword"]')
newPassword1 = self.driver.find_element_by_xpath('//*[#id="editNewUser_newPasswordRepeat"]')
newPasswordForm = self.driver.find_element_by_xpath('//*[#id="editNewUserPasswordForm"]/table/tbody/tr[1]/td[1]')
#gauurang Answer is right, But You have to used find_element_by_xpath, also as your xpath suggested you have id to locate the webelements so it is always better to use id over xpath
Also your xpath are correct
newPassword = self.driver.find_element_by_id('editNewUser_newPassword')
newPassword1 = self.driver.find_element_by_id('editNewUser_newPasswordRepeat')
newPasswordForm = self.driver.find_element_by_xpath('//*[#id="editNewUserPasswordForm"]/table/tbody/tr[1]/td[1]')
Coding in VS-2012 Express for Web -- VB.Net with this code...
Diagnostics.Debug.WriteLine(vbTab + ".prpUID_REPORT = [{0}]", .prpUID_REPORT)
Diagnostics.Debug.WriteLine(vbTab + ".prpRV_HeaderDSName = [{0}]", .prpRV_HeaderDSName)
Diagnostics.Debug.WriteLine(vbTab + ".prpRV_HeaderDSId = [{0}]", .prpRV_HeaderDSId)
Diagnostics.Debug.WriteLine(vbTab + ".prpRV_ReportDSName = [{0}]", .prpRV_ReportDSName)
Diagnostics.Debug.WriteLine(vbTab + ".prpRV_ReportDSId = [{0}]", .prpRV_ReportDSId)
Diagnostics.Debug.WriteLine(vbTab + ".prpRV_ReportPath = [{0}]", .prpRV_ReportPath)
Results in this in the Immediate-window:
.prpUID_REPORT = [22]
dsetCustHeader: .prpRV_HeaderDSName = [{0}]
SDS_RptHeader: .prpRV_HeaderDSId = [{0}]
dsetReportContentAll: .prpRV_ReportDSName = [{0}]
SDS_RptData: .prpRV_ReportDSId = [{0}]
ssrsFleetCostSummary_FLA.rdlc: .prpRV_ReportPath = [{0}]
Notice that the first debug-line shows the text correctly .prpUID_Report = [22]. However, the next debug-lines show the "value" followed by part of the source code line. It appears that the substitution into {0} is faulty.
Any clues as to what may be causing this? I think the debug-source code is syntactically correct, since the first line (= [22]) works as expected but the other lines do not.
Your comments are welcome.
Debug.WriteLine(string,string) method call is different from
Debug.WriteLine(string,object[])
which may be why the first WriteLine statement is working while the rest isnt as the second parameter is possibly a string.
Please check the documentation here
Have you tried using an explicit String.Format() call to see if that makes any difference?
Diagnostics.Debug.WriteLine(String.Format("{0} .prpUID_REPORT = [{1}]",vbTab, .prpUID_REPORT))
Diagnostics.Debug.WriteLine(String.Format("{0} .prpRV_HeaderDSName = [{1}]",vbTab, .prpRV_HeaderDSName))
` Other code omitted for brevity `
It may simply be an issue of the improper method call of the Debug.WriteLine() method (i.e. expecting an array or an object and just receiving a string, which is triggering the wrong functionality).
I made a CCMenu object and want to add an item to it but the menuWithItem() method appears deprecated and thus the item doesn't get added to my menu. Here is how am using it:
CCMenuItemFont* pExitButton = CCMenuItemFont::itemWithString(
"Exit",
this,
SEL_MenuHandler(CallbackOnExit));
CCMenu* pMenu = (CCMenu::menuWithItem(pExitButton, NULL);
what is the other possible way to get this done?
Try this:
CCMenuItemFont* pExitButton = CCMenuItemFont::itemFromString(
"Exit",
this,
SEL_MenuHandler(CallbackOnExit));