How do I retrieve a partial text from a website using selenium - selenium-webdriver

I am using selenium with both firefox and chrome and I was wondering on how to be able to get a certain part of a text and only that part.
<div align="center">
Your PR application has been submitted sucessfully.
<br>
Application Number :PR_____
<br>
PR number : _____
</div>
what if I only want the second part of the text?
Application Number :PR_____
How do I go about doing it?

You can try the following and 2nd index should contain the text you want. With xpath it's quite impossible
String text = driver.findElement(By.xpath("//div")).getText();
String[] trimmedText = text.split(":");
for (String str : trimmedText) {
System.out.println(str);
}
Print
Your PR application has been submitted sucessfully.
Application Number
PR_____
PR number

Related

Using Python Selenium - How to enter text on the web <p> tag

I am running into trouble, i am wondering how do i enter a custom text to a paragraph on a webpage.
The paragraph tag already has a default text example below [see Screenshot1]:
<p class="MuiTypography-root jss43 MuiTypography-body1">35 Years</p>
Screenshot1
I want to play with this tag to write my own text here lets say "25 Years".
Please assist!
I tried following:
I've requisite library imported
also check that there is no iframe..
gender = WebDriverWait(driver, 60).until(EC.presence_of_element_located(
(By.CLASS_NAME, 'MuiTypography-root')))
gender.click() # this click and i can see items
gender.send_keys('25 Years') # not working
gender.innerHtml('25 Years') # not working
try this element ((By.XPATH, '//div[#class="jss42"]/p') instead By.CLASS_NAME

Why UTF-8 Unicode in address bar vs GET form is difference in C?

I've developed a simple web page using C.
I will get the url address values and check them using strtok, strsep.
que=getenv("QUERY_STRING");
...
strcpy(val,strsep(&string,"="));
printf("%s<br>",val);
Browser Result when using <form method="GET">
E.g: When you type ۱ in an input field and press submit, it redirects to http://localhost/api?identifier=%26%231777%3B.
Output of getenv("QUERY_STRING") :
identifier=%26%231777%3B
Trying with different values:
۱ => %26%231777%3B
۲ => %26%231778%3B
۳ => %26%231779%3B
۱۲۳ => %26%231777%3B%26%231778%3B%26%231779%3B
It can easily be fixed using a function in the DecodeQueryStringC.
This is written by Max Base.
https://github.com/BaseMax/DecodeQueryStringC
decodeUrl(val,val);
printf("Fix:%s<br>",val);
Browser result when manually typed in the address bar
I am using Firefox 60.5.1esr (64-bit) and Chromium 71.0.3578.98 (Official Build) (64-bit).
E.g: When type ‍?identifier=۱ at the end of the http://localhost/api :
It redirects to http://localhost/api?identifier=%DB%B1 automatically by the browser.
Output of getenv("QUERY_STRING") :
identifier=%DB%B1
Trying with different values:
۱ => %DB%B1
۲ => %DB%B2
۳ => %DB%B3
۱۲۳ => %DB%B1%DB%B2%DB%B3
I also want to support when the user manually modifies the URL (link).
Guide me.
The percent-encoded string
%26%231779%3B
does not decode to ۱ but ۳ which is a HTML entity and not UTF-8. You shouldn't be using decodeHtmlEntities but just the decodeUrl. Likewise there is some code that is doing the redirect that is doing too much.
Don't know how about Arabic, in Hebrew there are different types of encoding. Like UTF8 and other ones,didn't fall into details but did you check that? I didn't anything with relevance to that in your post.

in Angular Entering Decimal Number in german format "having comma" is not work well

I am trying to localize the data entry Module (written in angular) based on the user PC (example in case the PC language setting is German ) so the module should accept the "," as a decimal separator instead of "." ,
So I have used the Angular localization files (e.g.: angular-locale_de-de.js ) However I have an issue when insert the decimal number using the comma as the following :
in German PC settings, when the users insert the decimal number at this format "5,4" at the input Text Box, the display at the Label to this value shows Empty instead of 5,40
the Label at the code as the following : <label>{{mynumber | number:2}}</label>
but when the user insert : "5.4" the label show "5,40"
for simplicity I am using the code below
<html>
<head>
<script LANGUAGE=javascript src="angular.js"></script>
<script LANGUAGE=javascript src="https://code.angularjs.org/1.2.9/i18n/angular-locale_de-de.js"></script>
</script>
</head>
<body ng-app >
<input type=number id="txt" ng-model="mynumber" >
<label>{{mynumber| number : 2}}</label>
</body>
</html>
And that also applied when using the filter below at the controller :
$filter('number')(mynumber, 2)
can you please help on how correctly format the number when insert number using comma separator (like above should be 5,40 instead of empty) ?
Please note : this problem is exist even using "angular-locale_de-de.js"
Also can you please advice on how can I load the right angular localization file (e.g.: angular-locale_de-de.js depending of the User Language PC settings )?
Thanks
There is angular directive (I am the author) which allow only numbers, minus sign and selected separator ',' or ','. Link: https://github.com/uhlryk/angular-dynamic-number
You can config number of integer digits, number of fraction digits, choose separator, or allow positive, negative or both numbers. It block other chars in input view value, but dynamically convert model value. This module also has filter to modify ngBind to show for example comma separator instead of dot.
After Installation (bower, npm or manualy) add module to your application as dependency, and then:
<input type="text" id="txt" ng-model="mynumber" awnum num-sep="," num-fract="2">
<label>{{mynumber| awnum : 2 : ',' : 'round' : 'true'}}</label>
I build this module to process forms with prices in Poland.
If you want to convert english number format into german number format. You can use following code in typescript -
const number = 123456.789;
console.log(new Intl.NumberFormat('de-DE').format(number));
// expected output: "123.456,79"
You can find more number formats and details here - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

How to upload a file using VBA (input file)

I have this CSV file that it need to be uploaded in a WebSite , but this website have an input type file.
I know its pretty impossible because i spent like three weeks loking for an answer,i found another way to upload the file WITHOUT USING THE INPUT TYPE FILE* so i was wondering if anyone found a solution to my probleme
This is what i have :
This is my firt attempt like any average personne using VBA :
Set UploadCSV = IEDoc.getElementById("namecsv")
UploadCSV.Value = "something\toto.csv"
This is my input type file:
<input name="filename" class="text align_center" id="nomfichiercsv" type="file" size="24" accept="text/html,text/plain" value=""/>
Thank's
I tried the SendKeys function no luck
Like mentioned you can do this in an Eclipse project using the Java Selenium driver. Afterwards part of the code could look like this;
driver.findElement(By.id("nomfichiercsv")).sendKeys(UploadCSV);
driver.findElement(By.id("submit")).click();
In VBA, you can use the below code after you have identified the element:
driver.FindElementById("Id of the element").SendKeys ("path to the input file")
If the frame changes when you are trying to upload the file, you will need to switch to the new frame.
If Id is not present for the element, use other Web Element selector methods.

Time out issue in classic ASP

I am working on a classic ASP project where I am getting time out issue when populating the data from DB and Bind it in the UI. The following error we got:
Script timeout
The maximum amount of time for a script tp execute was exceeded. You can change this limit by specifying new value for the property Server.Scripttimeout or by changing the value in IIS asministration tools
To resolve the issue we tried to do the pagination but it went unsuccessful.
There are several forms on one page with individual names (i.e. form1, form2) . We have implemented Recordset pagination within one particular form.
Along with the pagination edit and delete options are also available for a particular record in record set. The problem what we are facing is when we try to edit the record the form values are not coming to the posted page.
I have mentioned the code snippet as below:
Function someFunction
data1=""
<form name="Xyz" method="post" action="edit.asp">
s=s&"<script>function relsubmit() {alert(" & data1 &"); rjob.submit(); } </script>"
'Pagination code display only 30 records per page
Do While Not ( rss.Eof Or rss.AbsolutePage <> iPage )
'some code
If (Action="RELEdit") Then
s=s&"" & drsel &""
s=s&"
s=s&"" & clean(rss.Fields(4).value) & ""
Else
End If
datadr1=datadr1& rss.Fields(0).value & ","
rss.MoveNext
loop
If (Action="RELEdit") then
s=s&"<input type=hidden name=data1 value=""" & datadr1 & "">"
s=s&"<input type=hidden name=data2 value=""" &datadr2 & """><</form>"
End If
End Function
We have tried to get the value in edit.asp page using request.form("data1") the values are coming empty also we tried alert in the relsubmit() function it is showing as empty.
Can you please help me why the form values are posted as null or empty.
Also, please advise me if we have any other approaches to track the time out.
Place this code at the top of the ASP page you are running.
The values are in seconds (300 = 60*5 = 5 minutes)
This will extend the script runtime to 5 minutes. You can set any value even hours
<%Server.ScriptTimeout=600%>

Resources