How to Select checkbox in Appium using Python if there is no unique ID/Text/Class name - appium

Elements which i need to click
Element loator
Hi I am trying to click checkbox.
the below is my code
from appium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
desired_cap = dict(
platformName="Android",
platformVersion="11",
deviceName="1234567",
appPackage="io.appium.android.apis",
appActivity="io.appium.android.apis.ApiDemos"
)
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_cap)
driver.find_element(By.XPATH, "//android.widget.TextView[#text='Accessibility']").click()
driver.find_element(By.XPATH, "//android.widget.TextView[#text='Accessibility Node Querying']").click()
time.sleep(2)
chk= driver.find_elements(By.XPATH, "//android.widget.CheckBox")
for i in chk:
if i == 2:
i.click()
By above code if i give i.click() i am able to click all checkboxes. But if i want to click single check box i am not getting solution.

Select an array of elements and tap on its index
elements = self.driver.find_elements(*locator)
elements[i].click()

Related

Beautiful soup findAll returns empty list on this website?

I'm trying to extract property value history from this website:https://www.properly.ca/buy/home/view/ma-tEpHcSzeES-OlhE-V6A/bc/vancouver/1268-w-broadway-%23720/
But my code returns an empty list instead of the property cost history.
I used the following code:
from selenium import webdriver
import time
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
url= "https://www.properly.ca/buy/home/view/ma-tEpHcSzeES-OlhE-V6A/bc/vancouver/1268-w-broadway-%23720/"
driver.maximize_window()
driver.get(url)
time.sleep(5)
content = driver.page_source.encode('utf-8').strip()
soup = BeautifulSoup(content,"html.parser")
officials = soup.findAll("table",{"id":"property-history"})
for entry in officials:
print(str(entry))
Which returns an empty list, although this URL does have a property history table. Any help would be appreciated.
Thanks!
officials = soup.findAll("table",{"id":"property-history"})
On browser, I don't see a table with id="property-history" - but there is a div with that id, so maybe you can instead get the data you want through
officials = soup.find_all("div", {"id":"property-history"})
Btw, the only table I could find while inspecting the page was inside the map, and I don't think it holds any useful information for you.

How do get custom functions to recalculate in google sheets?

I created a custom function for google spreadsheets. All it does is return a random letter. The function works great when I first enter it into a cell. But now I want to be able to "recalculate" the function using a keyboard shortcut; I'd also be willing to refresh the page if needed.
TLDR: I want to be able to hit a key and have my custom functions recalculate.
How can I accomplish this?
Edit to add:
Here is the code for my function.
//returns a random letter suitable for use in function notation
function ranFunLet() {
var letters = ['a','b','c','d','f','g','h','j','k','m','n','p','q','r','s','t','u','v','w','x','y','z']
var letter = letters[Math.floor(Math.random()*letters.length)];
//console.log(letter);
return letter;
}
I would like the cell I use it in to run the function again when I press a button (or refresh the page).
Suggestion
The Apps Script editor does support keyboard shortcut trigger as per this existing answer. However, you may want to try Importing functions as macros, then you can assign a unique keyboard shortcut to it.
Here's a sample
Sample Sheet
Sample script function to test
This sample script function increments the number on A1 cell.
function sample() {
var data = SpreadsheetApp.getActive().getActiveSheet().getRange("A1").getValue();
var res = data+1;
SpreadsheetApp.getActive().getActiveSheet().getRange("A1").setValue(res);
}
Import the function on your spreadsheet (in my testing it is named as sample):
In the Google Sheets UI, select Tools > Macros > Import.
Select a function form the list presented and then click Add
function.
Select clear to close the dialog.
Select Tools > Macros > Manage macros.
Locate the function you just imported in the list. Assign a unique
keyboard shortcut to the macro. You can also change the macro name
here; the name defaults to the name of the function.
Click Update to save the macro configuration.
Result
After pressing the sample shortcut key Ctrl + Alt + Shift + 2, the function incremented the number on A1 cell from 1 to 2:
NOTE: You can not choose a specific shortcut & if you'll edit your function on the Apps Script editor, you would need to re-import your function again as a macro.
the button solution is done like this:
https://www.youtube.com/watch?v=yaBMsSpAxYM

Use Kivy app while excel file is being built

So I am trying to create a Kivy app that allows a user to control and monitor various hardware components. Part of the code builds and continuously updates an Excel worksheet that imports temperature readings from the hardware's comm port, along with a time-stamp. I have been able to implement all of this so far, but I am unable to interact with the Kivy app while the Excel worksheet is being built/updated (i.e. while my hardware test is underway), and leaves me unable to use the app's features while the test is running (Such as the 'Pause' or 'Abort' buttons) until the worksheet is no longer being altered. So my question is: Is it possible to export to an Excel file while being able to simultaneously use the Kivy app? And if so, how?
This is part of my code that sets up the Excel worksheet. Thank you in advance!
from kivy.app import App
from openpyxl import Workbook, load_workbook
import time
class HomeScreen(Screen):
def build(self):
return HomeScreen()
def RunExcelFile(self):
wb = Workbook()
ws = wb.active
a = 0
i = 2
while (a < 5):
ws.cell('A1').value = 'Time'
ws.cell('B1').value = 'Batch 1'
ws.cell('C1').value = 'Batch 2'
column = 'A'
row = i
time_cell = column + str(row)
t = time.localtime()
ws.cell(time_cell).value = time.asctime(t)
a = (a + 1)
i = (i + 1)
time.sleep(1)
wb.save("scatter.xlsx")
If you are doing some background job without touching widgets or properties, you can use threading module without problems. Otherwise, you would need to use #mainthread decorator or Clock.
import time
import threading
class HomeScreen(Screen):
def run_excel_file(self):
def job():
for i in xrange(5):
print i
time.sleep(1)
print 'job done'
threading.Thread(target=job).start()

How to get list of child elements of an element in Appium?

I'm working with native iOS app through Appium.
I have the following structure:
UIAApplication ->
UIAWindow ->
UIATextBox
UIALabel
UIAWindow ->
SomethingElse
I have found a way to get the first UIAWindow and I'd like to get the list of all elements in that window. How do I do that?
I'd like to get UIATextBox and UIALabel from first UIAWindow but NOT SomethingElse element.
How do I do list of child elements in general?
#Test
public void testListWindows() {
List<MobileElement> windows = driver.findElementsByClassName("UIAWindow");
List<MobileElement> elements = windows.get(0).?????
}
You're almost there. What you have is giving you a list of all UIAWindows when what you want is a list of all the elements of the first UIAWindow. I'd suggest using Xpath with a wildcard.
This will get you every element that is a direct child of the first UIAWindow:
List<MobileElement> elements = driver.findElements(MobileBy.xpath("//UIAWindow[1]/*");
And this will get you every child and sub-child and sub-sub-child etc. of the first UIAWindow:
List<MobileElement> elements = driver.findElements(MobileBy.xpath("//UIAWindow[1]//*");
An extra tip: If you're automating for iOS, I assume that means you have access to OS X, where you can install the Appium dot app and use inspector. The inspector is a great tool to test out xpath queries before putting them into your code.
You can also find textfield and label by its class for iOS app in Appium. findElementsByClassName method will return all elements on current screen that matches that class.
List<MobileElement> textFields = driver.findElementsByClassName("UIATextField");
MobileElement textField = textFields.get(0);
List<MobileElement> labels = driver.findElementsByClassName("UIAStaticText");
MobileElement label = labels.get(0);

Retrieving data via POST request

I am having trouble obtaining data programmatically from a particular webpage.
http://www.uschess.org/msa/thin2.php allows one to search for US Chess ratings by name and state.
Submitting a POST request, I can get to the equivalent of http://www.uschess.org/msa/thin2.php?memln=nakamura&memfn=hikaru but still requires one to clicking the "Search" button to get useful data. What is the best way to get to that results page?
import urllib.request
import urllib.parse
data = {'memfn':'hikaru', 'memln':'nakamura'}
url = r'http://www.uschess.org/msa/thin2.php'
s = urllib.parse.urlopen(url, bytes(urllib.parse.urlencode(data),'UTF-8'))
s.read()
Thanks!
This one works:
#!/usr/bin/env python
import urllib
data = {'memfn':'hikaru', 'memln':'nakamura', 'mode':'Search'}
url = r'http://www.uschess.org/msa/thin2.php'
s = urllib.urlopen(url, bytes(urllib.urlencode(data)))
print s.read()
Basically you need to submit hidden parameter mode with value Search to imitate the button press.
Note: I rewrote it for python 2.x, sorry, but I didn't have python3 handy.

Resources