how to make playwright to type in each character in a variable in to a search bar - playwright

there is a website (company website - cant share login) which has a search box containing locations
i was using fill to type in a randomly selected location from a dictionary
playwright fill in the entire location all at once
---
but the website search bar bugs out if u type in the all string at once.
only way to prevent the search bar from bugging out is type in each char
(i tried asking website owners to fix the search bar they dont seem interest)
i tired to following code but it keeps bugging out
parts of the code related to the search bar
import random
import time
import sys
random10 = ""
lda_10 = {
1: "bahria town - overseas A",
2: "bahria town - awais qarni block",
3: "bahria town - shaheen block",
4: "bahria town - shaheen block extension",
5: "bahria town - Ghouri block",
6: "bahria town - takbeer block",
7: "bahria town - Gulbahar Block",
}
def R_10():
global random10
random10 = random.choice(list(lda_10.values()))
for l in random10:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(0.2)
page.locator("#location_id_input").fill(random10)
page.locator("(//ul)[8]/li[1]").click
i expected the code to type in the chars but it just does not work

You could try to use page.type. It sends the events like a user typing on a keyboard would and you can also set a timeout to simulate a delay like a user would have.
await page.type("#location_id_input", random10, {delay: 100});

Related

Make cascading list mandatory on JIRA based on another cascading list

I think this can be achieved with behaviors but I am struggling with the code.
I am trying to make "Cascading list 2" mandatory when an option is picked from "Cascading list 1"
Eg:
On "Cascading list 1" if a user picks option "A" then they have to also fill out "Cascading list 2"
If they pick option "B" on "Cascading list 1" then "Cascading list 2" is not required.
This is some of the code I was playing around with:
def fieldA = getFieldByName('BI Reporting & Analytics Request Categories') //this is cascading list 1
def fieldC = getFieldByName('Reporting') //this is the cascading list 2
def fieldAValuesThatTriggerFieldCRequired = ['Reporting'] //this is the option choosen in cascading list 1
def valueA = fieldA.value
def fieldCIsRequired = valueA in fieldAValuesThatTriggerFieldCRequired
fieldC.setRequired(fieldCIsRequired)
Any assistance is appreciated.
Image on JIRA
Thanks.
If my understanding is correct, they are not cascading field.
The request here is that when field A has particular value saying 'aaa', then field B becomes required (mandatory).
This is a typical use case for Jira plugin Adaptavist ScriptRunner behaviours.
But Behaviours is only available for Jira server or data center version. It is not for Jira cloud.
If your Jira is server version, you can refer to below steps and scripts:
go to behaviours settings, if you don't have a behaviour item for
your workflow, please create it. If behaviour has been created,
click into action/edit.
choose the field A and add it.
click Add server-side script, you will see the black inline edit section.
add below code.
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
#BaseScript FieldBehaviours fieldBehaviours
FormField field1 = getFieldById(getFieldChanged()) // we need to capture the change in field 1.
FormField pmAuthor = getFieldByName("field2")
if (field1.getValue()) { // to check if field1 has value as the action on field could be a deleting value operation.
if (field2.getValue()=="A") {
field2.setRequired(true)
} else {
field2.setRequired(false)
}
} else { // if the value was deleted, then remove the requirement.
field2.setRequired(false)
}

IsTradeAllowed not returning what I would expect

Please see the script below:
void OnStart()
{
Alert(IsTradeAllowed()); //alert 1
Alert(IsTradeAllowed(NULL, TimeGMT())); //alert 2
Alert(IsTradeAllowed(Symbol(), TimeGMT())); //alert 3
Alert(IsTradeAllowed("GBPUSD", TimeGMT())); //alert 4
}
This returns:
true //for alert 1
true //for alert 2
false //for alert 3
false //for alert 4
As alert 2 returns: true, then I would expect alert 3 and alert 4 to return true.
I have tried running the code at multiple times of the day on weekdays. The code returns the same result at weekends. I have also tried putting the code in a script and an EA. Every time I get the same result. Is there an explanation for this? I have tried what is suggested here: https://www.mql5.com/en/docs/runtime/tradepermission
Symbol() returns: "GBPUSD". Each alert should return true in my mind, however this does not appear to be the case here. Incidentally I have notices that Symbol() returns the symbol at the top of the demo account watchlist if the script is run inside MetaEditor, however it returns the symbol displayed on the chart if run inside the demo account.
The broker is Oanda.
Update 04/03/21 at 19:55
I have now discovered that if I right click on the Market Watch and select: show all, then more symbols appear. I can then see that some symbols are greyed out and some symbols are not. The symbols that are not greyed out e.g. USDGBP-g return what I would expect when running the program above i.e. alert 1-alert 4 =true. The symbols that are greyed out e.g. USDGBP returns true; true; false; false in the program above. I now have two questions:
Why does: IsTradeAllowed(NULL, TimeGMT()); //alert 2 return true for symbols that are greyed out?
What does -g mean in GBPUSD-g?
IsTradeAllowed checks if the Expert Advisor is allowed to trade and trading context is not busy.
The version of the function without any arguments will check if the EA has been applied with the correct permissions ("Allow live trading" ticked and "AutoTrading" enabled).
The second form of the function:
bool IsTradeAllowed(const string symbol, datetime tested_time);
checks if the EA would be allowed to trade according to the specifications for the chart selected (to view this, from the Market Watch window right click a symbol, from the menu that pops up select "Specification").
For example
IsTradeAllowed(Symbol(), D'2021.03.06 12:00');
would check if the current symbol can be traded this coming Saturday (which should be false).
If you are getting undesirable results you should check that your broker has set the "Specifications" correctly.
EDIT
I've tested the command in OANDA which is the broker you are using and the command functions as expected.
NULL is not valid for a Symbol and its use makes the command function in its first form (ie timedate is ignored).
I would suggest rather than use Alerts to examine output, try the following.
string cmnt;
cmnt=StringConcatenate("Alert 1: ",IsTradeAllowed());
cmnt=StringConcatenate(cmnt+"\r\n","Alert 2: ",IsTradeAllowed(NULL, TimeGMT()));
cmnt=StringConcatenate(cmnt+"\r\n","Alert 3: ",IsTradeAllowed(Symbol(), TimeGMT()));
cmnt=StringConcatenate(cmnt+"\r\n","Alert 4: ",IsTradeAllowed("GBPUSD", TimeGMT()));
Comment(cmnt);
I tried your script in my ICMarkets version of MetaTrader4. With disabled auto trading i get result:
When I set auto trading to enable using Ctrl+E shortcut, in all cases script return true.
I recommend you to try this script on another account or different broker. If this will help, you should communicate with your broker about this issue. The last option is a reinstall MetaTrader to make sure, that all config files are correct.

Sqlite.swift live search

I want to do a live search on the DB.
Lets say I want to search by companies and I have the following info on a column named companies.
Facebook
FastCompany
Facebook
Google
Microsoft
I have a textfield that has calls a function on editchanged.
#IBAction func searching(sender: AnyObject) {
tempstring = "%"+searchBar.text+"%"
println(tempstring)
user = user.select(name)
.filter(like(tempstring, name))
.limit(30, offset: 0)
collectionView?.reloadData()
}
It kind of works, if I start typing "fa"
It will show (Facebook, Facebook and FastCompany)
If I continue typing "fac" it will show (Facebook, Facebook)
But when I delete the last character "c" from the searchbox (leaving it in "fa" again) then the query displays nothing.
Any ideas on how I can solve this.
I think your issue is coming from over writing the user object with each search. This is fine as long as you only move forward, but when you go backwards like you did, the query messes up.
Instead, try adding a currentQuery property to your view controller with the collection view in it and set it to your user.select statement.
currentQuery = user.select(name)
.filter(like(tempstring, name))
.limit(30, offset: 0)
Then use the currentQuery object to display the results instead. This way, no matter what you're searching, it will match everything.

Fetch Full Address based on Postal Code via Regex

I would like to grab the address highlighted in red. "Site Location:" can be easily identified via match(). However, how can I grab the highlighted part only without going over proceeding content, i.e., "You have applied...etc". Please note that the proceeding content won't always start with "You have applied".
What I would do is the following:
Look for "Site Location:"
Grab anything after "Site Location:" until you find empty/blank new line.
Can anyone help me achieving it in Ruby?
Note that the whole text is stored in a string variable.
regex = /\bSite Location:\s+(.*?)\n\s*\n/m
str = "Site Location: Raglan Street
Collingwood Town, Some County
You have applied..."
if md = regex.match(str)
address = md[1].strip.gsub(/^\s+/,'')
puts address
end
Output:
Raglan Street
Collingwood Town, Some County
Note: one thing to watch for is the possibility of different types of newlines. E.g. Microsoft may use \r\n\r\n, etc. in which case you may have to adjust regex accordingly.

How can I format a post request to http://iswcnet.cisac.org/ to search without having to start from within the site?

I'm looking to open search results at http://iswcnet.cisac.org/ with the search parameters POSTed from a Greasemonkey form on another site. Plus, I hate their search interface; it'd be nice to write my own GM wrapper for it, if only I could find how to format the search.
Use URL http://iswcnet.cisac.org/iswcnet/MWI/search.do?
parameters:
firstCriteria=
What to search:
titleFirstCriteria - Title
iswcFirstCriteria - ISWC number
ipNameMwiFirstCriteria - Creator's Name
ipNameNumberFirstCriteria - Creator-Id
firstCriteriaType=
Search type:
E - 'exact'
B - 'begins with'
W - 'contains'
firstCriteriaInput= {the search term}
Example: Search for any work entry by anyone whose name contains "Cobain":
http://iswcnet.cisac.org/iswcnet/MWI/search.do?firstCriteria=ipNameMwiFirstCriteria&firstCriteriaType=B&firstCriteriaInput=Cobain

Resources