Value of next element is entered in current element - python-3.x

I want to enter the "Password" element using Python (Selenium). The first element entered is User ID, next is Password element.
The problem is when i enter the "Password" after entered the User ID, the value for User ID has no problem. But, when value of Password is entered, it is entered in User ID field.
Eg:
User ID: Ain
Password: abc
System enter the password in User ID field.So, it will be shown like this,
User ID: Ainabc
Password: (blank)
Code trials:
filepath = "C:/Users/siti11074/Payroll Master/login_test.xlsx"#Config file
wb = load_workbook(filepath)
config_sheet = wb.get_sheet_by_name('Config')
b2=config_sheet['C3']
user_id = b2.value
b3=config_sheet ['C4']
password = b3.value
driver.find_element_by_id("USERID_I").send_keys(user_id)
time.sleep(2.0)
print("User ID is entered")
elem_pwd=driver.find_element_by_id("USERPWD_I")
ActionChains(driver).move_to_element(elem_pwd).send_keys(password).perform()
time.sleep(2.0)
print("Password is entered")
Expected Result:
System need to enter the User ID value in User ID field.
And for Password value in Password field.

Related

How to trim username from email id in terraform

How to drop everything after # in email id in terraform
count = length(local.admin_users)
username = "${trimspace(local.admin_users[count.index])}_default"
It gives me test#gmail.com_default
I want test_default
How can this be accomplished in terraform
You could split the admin_user based on # character and use its first part:
username = "${split("#", trimspace(local.admin_users[count.index]))[0]}_default"

can I call a function to set my USERNAME_FIELD = ''?

can I call a function in USERNAME_FIELD = '' to create an optional choice for login, using email or phone number? if yes how?
yes, you can
you can write special login function in your view and use query like this :
user = User.objects.filter(Q(email=value)|Q(username=value)).first()
login(request, user)
I use Q django db functions to complex query and I can use Or in my queries for example in up code I filter email equal by value or username equal by value so if uaer enter username or email I can find him
in other ways I can use two query but its not common
like this :
user_by_username=User.objects.filter(usernsme=value).first()
if user_by_username:
login(request,user)
else:
user_by_email=User.objects.filter(email=value).first()
if user_by_email:
login(request,user_by_email)
and default user model hasn't mobile field you can save mobile as username or create special usermodel
or create new model for your user profile

Getting wrong User ID from self._uid

I'm trying to get the logged in user's id from self._uid. But when I logged in with a user and I got the user_id = 1 (which is the user_id of the administrator account)
That is my line. Am I doing something wrong?
user_id = self._uid
Replace your code
from
user_id = self._uid
to
user_id = self.env.user
These will give us current logged user as a recordset. So if you need id, get it like self.env.user.id

Need to execute SQL query dynamically

I need to update name of customer using the input provided by the user.
original_name need to be updated by new_name
cur.execute('''
CREATE TABLE customer (customerId int,customerName varchar(20),telephoneNo int,
addressId varchar(20), customerType varchar(20),
discount int, memCardType varchar(20))''')
I'm trying to perform this code, but it gives an error.
original_name=input("Enter name to be modified: ")
new_name=input("Enter new name of the customer: ")
cur.execute("UPDATE customer SET customerName=new_name WHERE customerName=original_name ")
print("Customer name changes successfully.")
Error:
cur.execute("UPDATE customer SET customerName=new_name WHERE
customerName=original_name ")
cx_Oracle.DatabaseError: ORA-00904: "ORIGINAL_NAME": invalid identifier
I suppose you use a SQL cursor so I would do it like that :
original_name=input("Enter name to be modified: ")
new_name=input("Enter new name of the customer: ")
cur.execute("UPDATE customer SET customerName=:new_name WHERE customerName=:cust_name",{'cust_name': original_name, 'new_name' : new_name})
print("Customer name changes successfully.")
The concept is simple. :new_name and :cust_name are binding parameters, in fact you told to your function you will add this parameter as variable then in
{'cust_name': original_name, 'new_name' : new_name}
You just fill those binding parameters with your variables.

Go, extract days out of byte array

I have a byte array containing the output of an Active Directory call. I want to parse this and extract the amount of days until my account expires. Now I'm wondering: what's the best way to extract 22-4-2016 11:05:26 (so the value after Password Expires)?
[]byte(`The request will be processed at a domain controller for domain local.nl.bol.com.
User name bla
Full Name bla bla
Comment
User's comment
Country code (null)
Account active Yes
Account expires Never
Password last set 13-3-2016 11:05:26
Password expires 22-4-2016 11:05:26
Password changeable 13-3-2016 11:05:26
Password required Yes
User may change password Yes
Workstations allowed All
Logon script bla.bat
User profile
Home directory
Last logon 31-3-2016 7:59:29
Logon hours allowed All
The command completed successfully.`)
Using strings.TrimSpace, strings.Index and referring to related stackoverflow answers, I got a working solution and please find working code below:-
package main
import (
"fmt"
"strings"
)
func CToGoString(c []byte) string {
n := -1
for i, b := range c {
if b == 0 {
break
}
n = i
}
return string(c[:n+1])
}
func main() {
s := []byte(`The request will be processed at a domain controller for domain local.nl.bol.com.
User name bla
Full Name bla bla
Comment
User's comment
Country code (null)
Account active Yes
Account expires Never
Password last set 13-3-2016 11:05:26
Password expires 22-4-2016 11:05:26
Password changeable 13-3-2016 11:05:26
Password required Yes
User may change password Yes
Workstations allowed All
Logon script bla.bat
User profile
Home directory
Last logon 31-3-2016 7:59:29
Logon hours allowed All
The command completed successfully.`)
d := CToGoString(s)
len := len("Password expires")
i := strings.Index(d, "Password expires")
j := strings.Index(d, "Password changeable")
chars := d[i+len:j]
fmt.Println(strings.TrimSpace(chars))
}
Have posted code to playground: http://play.golang.org/p/t0Xjd04-pi
You can do it by converting the []byte into a string and then using the strings package to find and extract the value and finally parsing it with time.Parse to convert the string to a time that you can work with.
package main
import (
"fmt"
"strings"
"time"
"log"
)
func main() {
line := data[strings.Index(data, "Password expires"):strings.Index(data, "Password changeable")]
date := strings.TrimSpace(strings.TrimPrefix(line, "Password expires"))
fmt.Println(date)
pDate, err := time.Parse("02-1-2006 03:04:05", date)
if err != nil {
log.Fatal(err)
}
fmt.Println(pDate)
}
var data = string([]byte(`The request will be processed at a domain controller for domain local.nl.bol.com.
User name bla
Full Name bla bla
Comment
User's comment
Country code (null)
Account active Yes
Account expires Never
Password last set 13-3-2016 11:05:26
Password expires 22-4-2016 11:05:26
Password changeable 13-3-2016 11:05:26
Password required Yes
User may change password Yes
Workstations allowed All
Logon script bla.bat
User profile
Home directory
Last logon 31-3-2016 7:59:29
Logon hours allowed All
The command completed successfully.`))
On the playground.

Resources