Dear All in Stackover flow,
I need your help :
I need to handle change input of bodytemperature
Picture of Web change body temperature
I need input this body temperature with random value between 35.8 - 36.5
This is inspect elements :
<input data-val="true" data-val-number="The field BodyTemperature must be a number." data-val-range="The field BodyTemperature must be between 33 and 43." data-val-range-max="43" data-val-range-min="33" data-val-required="The BodyTemperature field is required." id="BodyTemperature" max="43" min="33" name="BodyTemperature" step="0.1" type="text" value="36.1" data-role="numerictextbox" role="spinbutton" aria-valuemin="33" aria-valuemax="43" class="k-input" aria-valuenow="36.1" aria-disabled="false" style="display: none;">
And this is my code try
input_value = [36.10 ,36.20 ,36.30,36.50,35.80,35.90,35.80]
value = random.choice(input_value)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH,//input[#id='BodyTemperature'])).send_keys(value)
I hope Stackoverflow can help me
Please Help Me !!!!
For decimal values you have to use double, Please try the below, I have checked it it's giving the random number between 35.8 - 36.5.
double min = 35.8;
double max = 36.5;
double diff = max - min;
double randomValue = min + Math.random( ) * diff;
System.out.println(String.format("%.3g%n", randomValue))
Result: Like 36.1, 36.2, 35.9
Let us know if it didn't work for you.
Related
SAMPLE: I have sales in two days and I formatted each value per day in Currency
Dim firstSales,secondSales as String
firstSales = 1500
secondSales = 1500
Me.firstDaySales.Caption = FormatCurrency(firstSales)
Me.secondDaySales.Caption = FormatCurrency(secondSales)
I got the right format for each value per day in caption
Me.totalSales.Caption = Val(firstDaySales) + Val(secondDaySales)
But when I try to get the total Sum of Val(firstDaySales) and Val(secondDaySales) I got the wrong answer "0" beacause the value of Val(firstDaySales) and Val(secondDaySales) become "?1,500.00", it didn't recognize as a number or currency.
How to solve it?
Thank You.
Add the values, not the captions, then format
Dim firstSales As Double
Dim secondSales as Double
firstSales = 1500
secondSales = 1500
Me.firstDaySales.Caption = FormatCurrency(firstSales)
Me.secondDaySales.Caption = FormatCurrency(secondSales)
Me.TotalSales.Caption = FormatCurrency(firstSales + secondSales)
I've checked already multiple similar questions and answers, but unfortunately didn't found any solution for my particular case.
Issue description
I'm trying to fill out and submit the form on this site. The form was build as follow:
<form id="hikuZR" action="/historische-kurse/BMW" method="post">
...
<div class="hidden"><input type="submit" value="senden"></div>
<span class="button bgBlue btn-xs-block pull-sm-right" onclick="submitForm($(this));">Historische Kurse anzeigen</span>
</div>
<input type="hidden" name="pkBHTs" value="1550956687">
</form>
This is how I'm performing it:
Filling out the form
start_day_1 = self.driver.find_element_by_xpath("//select[#name='inTag1']/option[#value=22]")
start_day_1.click()
start_day_2 = self.driver.find_element_by_xpath("//select[#name='inTag2']/option[#value=22]")
start_day_2.click()
start_month_1 = self.driver.find_element_by_xpath("//select[#name='inMonat1']/option[#value=08]")
start_month_1.click()
start_month_2 = self.driver.find_element_by_xpath("//select[#name='inMonat2']/option[#value=08]")
start_month_2.click()
start_year_1 = self.driver.find_element_by_xpath("//select[#name='inJahr1']/option[#value=2018]")
start_year_1.click()
start_year_2 = self.driver.find_element_by_xpath("//select[#name='inJahr2']/option[#value=2018]")
start_year_2.click()
try:
market = self.driver.find_element_by_xpath("//select[#name='strBoerse']/option[#value='%s']" % 'XETRA')
market.click()
sleep(randint(7, 10))
except NoSuchElementException:
print("Element by xpath does not exist!")
This part works fine, and I'm able to put all values to the form:
Clicking on the Button:
I'm trying to locate the button by XPATH as well:
hist_button = self.driver.find_element_by_xpath("//span[contains(.,'Historische Kurse anzeigen')]")
and to click on this button, which seems to be found:
hist_button.click()
It doesn't work for me. I've tried also performing the button by executing the script as proposed in some answers on SO:
self.driver.execute_script("arguments[0].click();", hist_button)
Also this solution doesn't work in my case. The page has been refreshed, but didn't show me the result for the historical dates:
This is what I see after manual clicking on the button:
Could you please help me to find out, what I'm doing wrong? Thank you.
Update 25.02.2018
As suggested in the comment, I'm selecting the values from DropDown lists with the Select class as follow:
start_day_1 = Select(self.driver.find_element_by_xpath("//select[#name='inTag1']"))
start_day_1.select_by_value("22")
start_day_2 = Select(self.driver.find_element_by_xpath("//select[#name='inTag2']"))
start_day_2.select_by_value("22")
start_month_1 = Select(self.driver.find_element_by_xpath("//select[#name='inMonat1']"))
start_month_1.select_by_value("8")
start_month_2 = Select(self.driver.find_element_by_xpath("//select[#name='inMonat2']"))
start_month_2.select_by_value("8")
start_year_1 = Select(self.driver.find_element_by_xpath("//select[#name='inJahr1']"))
start_year_1.select_by_value("2018")
start_year_2 = Select(self.driver.find_element_by_xpath("//select[#name='inJahr2']"))
start_year_2.select_by_value("2018")
market = Select(self.driver.find_element_by_xpath("//select[#name='strBoerse']"))
market.select_by_value('XETRA')
And I'm seeing the selected values in the form (with the "first" version posted in the description, I saw the values in the form as well). After that I'm clicking the button again without any effects. The page was refreshed, but I don't see the results:
hist_button = self.driver.find_element_by_xpath("//span[contains(.,'Historische Kurse anzeigen')]")
hist_button.click()
html_historical = self.driver.page_source
or
hist_button = self.driver.find_element_by_xpath("//span[contains(.,'Historische Kurse anzeigen')]")
self.driver.execute_script("arguments[0].click();", hist_button)
html_historical = self.driver.page_source
When I click on the button manually, the result for selected data will show correctly. It looks like the performing of the button is not working.
OK, I have a customer name and address and simply want to display this in one computed field instead of separate lines in a table to save real estate. I've tried several iterations of #newline but to no avail. Can someone give me some guidance?
I would also like to NOT include Address2 if it's blank. I'm new to javascript. Thanks for your help.
var a = document1.getItemValueString("CompanyName");
var b = document1.getItemValueString("Address1");
var c = document1.getItemValueString("Address2");
var d = #Char(13);
a + #NewLine() + b + "<br>" + c;
Set property escape="false" in computed field and add <br /> whenever you want a newline.
You can set this property in properties tab selecting content type "HTML" too:
Your code would be
var a = document1.getItemValueString("CompanyName");
var b = document1.getItemValueString("Address1");
var c = document1.getItemValueString("Address2");
a + "<br />" + b + (c ? "<br />" + c : "");
Mike,
I had to do nearly the same thing recently and used a Multiline Edit Box. Place your same code in data section of an <xp:inputTextArea> (Multiline Edit Box in palette) and then make it read-only.
For a legacy Classic ASP application, I am supposed to remove all security attack issues. Currently, DB contains data which is already encoded and there will be no more Insert/update operations. Only select operations from now on wards.
I am able to remove SQL Injection and few other security issues, but, unable to remove
Cross Site Scripting (XSS) : Poor Validation Issue
This became bottle neck for delivery of the project.
Could anybody help me on this.
Example:
My data in DB as following.
One Cell Sample Data (Korean and English Char)
1.. Rupture disc 설치 관련 필요 자재 List<BR>──────────────────────────────────────<BR> No 필요 자재 재질 비 고 <BR>──────────────────────────────────────<BR> 1 inlet isolation valve, 8" Hast C276 기존 재고 사용 <BR> 2 RD holder inlet/outlet Hast C276 / 316L 신규 구매 <BR> 3 Rupture Disc Hast C276 신규 구매 <BR> 4 SV outlet isolation valve, 10" SUS 316L 신규 구매 <BR>──────────────────────────────────────<BR><BR>2. Rupture Disc Specification<BR> 1) Rupture design press : 4kg/cm2<BR> 2) Design temperature : 100℃<BR> 3) Rupture press tolerance : ± 5%<BR> 4) Manufacturing range : + 0%, - 10%<BR> 5) Material spec : M1, M4, C31<BR> 6) Max. allowable oper press : 3.2kg/cm2 (at 100℃)<BR><BR>3. Rupture Disc spec 선정 기준<BR> . Code, Standard = API 520, ASME VIII<BR> . Required Burst Pressure = Vessel Design Pressure<BR> . Manufacturing range(+0% ∼ -10%) of Required Burst Pressure<BR> . Rupture Pressure Tolerance +5%, -5% of Stamped Burst Pressure<BR> . Specified Disc Temperature = Actual Temperature of Disc in Operation <BR> → usually lower at disc than in liquid phase of vessel <BR><BR>4. Rupture Disk 전단 및 SV2209 후단 Isolation valve는 CSO(CAR SEAL OPEN) .<BR><BR>5. Rupture Disk 후단에 PG2209를 설치하여 운전 중 Rupture disk 파손 여부 확인 가능토록 함.<BR>
I am displaying above cell data as follows:
Sample Page:
<!-- #include file="INCLUDES/HTMLDecode.inc" -->
.
.
.
<HTML>
.
.
.
sampledata = rs("sampledata")
.
.
.
<TD><%= ClearForAttack(sampledata) =%></TD>
.
.
.
</HTML>
The above functions defined as follows :
User Defined Functions:
<%
Function HTMLDecode(sText)
Dim I
sText = Replace(sText, """, Chr(34))
sText = Replace(sText, "<" , Chr(60))
sText = Replace(sText, ">" , Chr(62))
sText = Replace(sText, "&" , Chr(38))
sText = Replace(sText, " ", Chr(32))
For I = 1 to 255
sText = Replace(sText, "&#" & I & ";", Chr(I))
Next
HTMLDecode = sText
End Function
%>
<%
Function ClearForAttack(pStrValue)
if len(pStrValue)>0 then
pStrValue = HTMLDecode(Server.HTMLEncode(pStrValue))
pStrValue = replace(pStrValue,"'","")
pStrValue = replace(pStrValue,"`","")
pStrValue = replace(pStrValue,"%","")
pStrValue = replace(pStrValue,"<","<")
pStrValue = replace(pStrValue,">",">")
else
pStrValue = ""
end if
ClearForAttack = pStrValue
End Function
%>
To display already encoded data I am using both HTMLDecode and HTMLEncode Functions
Please EDIT functions or suggest me another approach.
Your help or suggestions are highly appreciated.
Thanks in advance.
As stated, simply sanitise the post/query string data all data from user input and the database alike. You can try a number of methods including Server.HTMLEncode.
If you need to extend this to cover database fields, then you're going to need to perform some kind of search and replace on < and >, replacing them with < and > respectively.
There are some problems with XSS. You may want to read this first.
The Server.HTMLEncode sanitizes the query. You need to run a validation process to satisfy the poor validation. There is a simple "blacklist" program that you can change to suit your needs. check http://blogs.iis.net/nazim/filtering-sql-injection-from-classic-asp or Validation for Form and QueryString in ASP Classic using Regex. Almost working but missing something?. Once incorporated, should remove most of poor validation.
I need a way to find the difference between two strings in a Windows application using VBScript. One of the strings is known but the second one is completely unknown during coding. I know there are functions like StrCompare, InStr etc. but these require you to know the second string also during coding.
Explanation:
There is a text box in the screen and there are several buttons in the same screen. As and when the buttons are clicked, the text in the text box changes depending on the button clicked. Is there a way to find the changes made to the text after the button is clicked ? Basically I need to get the text entered due to the button click. Is there a simple way to do this or it requires complex coding ?
Thanks in Advance.
It depends on your application and the format of the new string.
If you need to find the text appended to the original string, you could take the new text and simply replace the first occurrence of the original string with an empty string:
Dim strOld, strNew, strDiff
strOld = "Apple"
strNew = "Apple, Orange"
strDiff = Replace(strNew, strOld, "", 1, 1)
WScript.Echo strDiff
Sample output:
, Orange
Or if you need to get the appended text without the preceding comma, you could use something like this:
strDiff = Replace(strNew, strOld + ", ", "", 1, 1)
To access (read/write) the content of a HTML text input you need to get the HTML element (document.all.<Name/Id> or document.getElementById(<Name/Id>) and its .value; as in this demo:
<html>
<head>
<Title>readtext</Title>
<hta:application id="readtext" scroll = "no">
<script type="text/vbscript">
Function Change()
document.all.txtDemo.value = "Changed Value"
End Function
Function Check()
Dim txtDemo : Set txtDemo = document.getElementById("txtDemo")
Dim sDemo : sDemo = txtDemo.value
Select Case LCase(Trim(sDemo))
Case "initial value"
MsgBox "still: " & sDemo
Case "changed value"
MsgBox "now: " & sDemo
Case Else
MsgBox "surpise: " & sDemo
End Select
End Function
</script>
</head>
<body>
<input type="text" id="txtDemo" value="Initial Value" />
<hr />
<input type="button" value="Change" onclick="Change" />
<input type="button" value="Check" onclick="Check" />
</body>
</html>