Unable to Iterate Integer in list using selenium python - python-3.x

I am trying to build a code which automatically fill the text field in textbox,These codes are working as string in list but cant able to iterate integer .
I have tried to do many steps but this is not working ,however code is working in python .
elem = browser.find_element_by_name("pwd")
elem.send_keys("oyo#1234")
time.sleep(2)
elem = browser.find_element_by_name('Submit').click()
elem = browser.find_element_by_name('login_existing_agent').click()
time.sleep(2)
browser.find_element_by_xpath("/html/body/table/tbody/tr/td[2]/div/img").click()
#browser.find_element_by_xpath("/html/body/div[4]/table/tbody/tr/td[1]/table/tbody/tr[2]/td/ul[2]/li[3]/a").click()
time.sleep(1)
browser.find_element_by_xpath("/html/body/div[4]/table/tbody/tr/td[1]/table/tbody/tr[2]/td/ul[2]/li[3]/a").click()
agent_id = [4600000 ,4600001 , 4600002]
a = len(agent_id)
agent_name = [ "saurav" ,"nishant", "vikash"]
b = len(agent_name)
sip_pass = ["Oyo4600000" ,"Oyo4600001" , "Oyo4600002"]
c = len(sip_pass)
i = 0
j =0
k =0
while ( i< a and j<b and k<c ) :
elem = browser.find_element_by_name('agent_add_ui').click()
elem = browser.find_element_by_name('agent_secret')
elem.send_keys("123456")
dropdown = browser.find_element_by_xpath("//*[#id='campaign_id']")
select =Select(dropdown)
select.select_by_visible_text('GOOGLE')
elem = browser.find_element_by_name('agent_id')
elem.send_keys(agent_id[i])
elem = browser.find_element_by_name('agent_name')
elem.send_keys(agent_name[j])
elem = browser.find_element_by_name('sip_pass')
elem.send_keys(sip_pass[k])
elem = browser.find_element_by_name('add_agent').click()
i += 1
j += 1
k += 1
browser.close()

You'll have to first convert each item in your list of integers, into a string, before specifying the item via its index within 'send_keys', not to worry, str() will do the trick :)
elem.send_keys(str(agent_id[i]))

Related

Get method doesn't return defined optional value

This is the code I am working with :
newResults = True
pages = 9
while newResults:
Request = f"{url}?key={API_Key}&ts={ts}&hash={hash}&project_id={project_id}&per_page= {per_page}&page={pages}&date_from={date_from}&date_to={date_to}"
r = requests.get(Request)
data = r.json()
for id in data['tickets']:
newResults = id.get('id', False)
pages += 1
Once the code gets to the newResults = id.get('id', False) and the key doesn't exist, it breaks. Tried using an empty list, tried using a string. Tried printing newResult to see what's going on.It doesn't print the optional value.
The loop goes on forever.
What am I getting wrong?
Still no idea why .get() doesn't return False, but here is a way to do it.
newResults = True
pages = 9
while newResults :
ticketsRequest = f"{url}?key={API_Key}&ts={ts}&hash={hash}&project_id={project_id}&per_page={per_page}&page={pages}&date_from={date_from}&date_to={date_to}"
r = requests.get(ticketsRequest)
data = r.json()
total = data['total']
for id in data['tickets']:
#stuff to do
result += 1
pages += 1
if result == total:
print (project_id, total, result)
break

why Lists in a class were changed without my operate?

i run a class in a for cycle.
the code is:
graph_all = []
graph_now = graph_exc(-1)
for lin in res_str:
if lin.strip():
print(lin)
if lin[0] == 't' :
if graph_now.numbering != (-1) :
graph_all.append(graph_now)
graph_now = graph_exc(int(lin[4:-1]))
if lin[0] == 'v' :
graph_now.add_vertex(lin[2],lin[4])
if lin[0] == 'e' :
graph_now.add_edges(lin[2],lin[4],lin[6])
else:
continue
res_str is a list full of sentences.
I use graph_all to accommdate all the class.
when the first letter is 'v' or 'e',i put something in graph_now's lists.
when the first letter is 't',i put graph_now to graph_all and re-define the graph_all.but i find a problem:when i define graph_all again,the lists in class in graph_all will be nothing,too!
the code of graph_exc is :
class graph_exc:
edges_on_1 = []
edges_on_2 = []
edges_on_edges = []
vertex_on = {}
def __init__(self,numbering):
self.num_edge = 0
self.num_vertex = 0
self.numbering = numbering
self.edges_on_edges.clear()
self.edges_on_2.clear()
self.edges_on_1.clear()
self.vertex_on.clear()
def add_vertex(self,ver,ver_num):
self.vertex_on[ver] = ver_num
self.num_vertex += 1
def add_edges(self,point_1,edges,point_2):
self.edges_on_1.append(point_1)
self.edges_on_edges.append(edges)
self.edges_on_2.append(point_2)
self.num_edge += 1
the problem is : edges_on_1,edges_on_edges,edges_on_2 and vertex will be influenced.the data in here will disappear.but the num_edge and num_vertex are not.
I try to use deepcopy method to solve it.but it does not work.

SymPy : Cancel out unnecessary variables and coefficients

I have an expression like :
b = IndexedBase('b')
k = IndexedBase('k')
w = IndexedBase('w')
r = IndexedBase('r')
z = IndexedBase('z')
i = symbols("i", cls=Idx)
omega = symbols("omega", cls=Idx)
e_p = (-k[i, omega]*r[i]/w[i] + k[i, omega]*r[i]/(b[omega]*w[i]))**b[omega]*k[i, omega]*r[i]/(-b[omega]*k[i, omega]*k[i, omega]**b[omega]*r[i]*z[omega]/w[i] + k[i, omega]*k[i, omega]**b[omega]*r[i]*z[omega]/w[i])
e_p = simplify(e_p)
print(type(e_p))
print(e_p)
<class 'sympy.core.mul.Mul'>
-(-(b[omega] - 1)*k[i, omega]*r[i]/(b[omega]*w[i]))**b[omega]*k[i, omega]**(-b[omega])*w[i]/((b[omega] - 1)*z[omega])
So k[i, omega] should be canceled out when I use simplify() function but do nothing. How can I get rid of unnecessary variables and coefficients?

convert string list to decimal list to 10 decimal points in python

How to convert folowing list:
['524.7940719572', '0.1874483617', '0.0321140582', '228.8002278843', '6843.5984811891', '29.9108027316', '60.2048797607', '220.7372120052', '556.828334181']
to:
[524.7940719572, 0.1874483617, 0.0321140582, 228.8002278843, 6843.5984811891, 29.9108027316, 60.2048797607, 220.7372120052, 556.828334181] in python
l = ['524.7940719572', '0.1874483617', '0.0321140582', '228.8002278843', '6843.5984811891', '29.9108027316', '60.2048797607', '220.7372120052', '556.828334181']
i = 0
for v in l:
l[i] = float(v)
i = i+1
print l
results the following output:
[524.7940719572, 0.1874483617, 0.0321140582, 228.8002278843, 6843.5984811891, 29.9108027316, 60.2048797607, 220.7372120052, 556.828334181]

Compare to string of names

I am trying to compare the names of two strings, and trying to pick out the name that are not included in the other string.
h = 1;
for i = 1:name_size_main
checker = 0;
main_name = main(i);
for j = 1:name_size_image
image_name = image(j);
temp = strcmpi(image_name, main_name);
if temp == 1;
checker = temp;
end
end
if checker == 0
result(h) = main_name;
h = h+1;
end
end
but it keeps returning the entire string as result, the main string contain roughly 1000 names, the images name contain about 300 names, so it should return about 700 names in result but it keep returning all 1000 names.
I tried your code with small vectors:
main = ['aaa' 'bbb' 'ccc' 'ddd'];
image = ['bbb' 'ddd'];
name_size_main = size(main,2);
name_size_image = size(image,2);
h = 1;
for i = 1:name_size_main
checker = 0;
main_name = main(i);
for j = 1:name_size_image
image_name = image(j);
temp = strcmpi(image_name, main_name);
if temp == 1;
checker = temp;
end
end
if checker == 0
result(h) = main_name;
h = h+1;
end
end
I get result = 'aaaccc', is it not what you want to get?
EDIT:
If you are using cell arrays, you should change the line result(h) = main_name; to result{h} = main_name; like that:
main = {'aaa' 'bbb' 'ccc' 'ddd'};
image = {'bbb' 'ddd'};
name_size_main = size(main,2);
name_size_image = size(image,2);
result = cell(0);
h = 1;
for i = 1:name_size_main
checker = 0;
main_name = main(i);
for j = 1:name_size_image
image_name = image(j);
temp = strcmpi(image_name, main_name);
if temp == 1;
checker = temp;
end
end
if checker == 0
result{h} = main_name;
h = h+1;
end
end
You can use cells of string along with setdiff or setxor.
A = cellstr(('a':'t')') % a cell of string, 'a' to 't'
B = cellstr(('f':'z')') % 'f' to 'z'
C1 = setdiff(A,B,'rows') % gives 'a' to 'e'
C2 = setdiff(B,A,'rows') % gives 'u' to 'z'
C3 = setxor(A,B,'rows') % gives 'a' to 'e' and 'u' to 'z'

Resources