Can I use ng2-file-upload with button instead of a file input? - file-upload

I'm using ng2-file-upload (single upload example) and I want to use: ng2FileSelect with a button or a div instead of a file input. How can I do this?
I want this to do something like this:
<button ng2FileSelect [uploader]="uploader">Choose file</button>
Instead of:
<input type="file" ng2FileSelect [uploader]="uploader" />
If does not exist a clean way using ng2-file-upload, do you know an alternative?

One possible solution is to leverage Angular 2's template variables, and to assign a template variable to the input element; once done, you can directly invoke methods defined on that input from another element, such as a button.
I did the following in one of my applications; it works on IE11, Firefox, and Chrome:
<button (click)="fileInput.click()" class="btn btn-default">Upload</button>
<span style="visibility: hidden; position: absolute; overflow: hidden; width: 0px; height:0px;border:none;margin:0; padding:0">
<input type="file" #fileInput ng2FileSelect [uploader]="uploader" />
</span>
So as you can see, the button is simply calling the #fileInput's click event within its own click event.
Note that I'm burying the input within a span, and then hiding the span from view via a bunch of styles, such that only the button is visible. Also note that applying these styles to the input element directly seemed to cause problems in IE11.

Yon can wrap input[file] element with label element and hide it. See this answer and this example
Here's the code.
HTML:
<label for="file-upload" class="custom-file-upload">
<i class="fa fa-cloud-upload"></i> Custom Upload
</label>
<input id="file-upload" type="file"/>
CSS:
input[type="file"] {
display: none;
}
.custom-file-upload {
border: 1px solid #ccc;
display: inline-block;
padding: 6px 12px;
cursor: pointer;
}

In a simple way, you can do it with label, you just have to hide the input.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<label class="btn custom-input-btn">
<input type="file" name="photo" style="display:none" accept="*" multiple>
<i class="fa fa-cloud-upload"></i> Upload Files
</label>

Related

Bootstrap v5.2 radio inputs/labels will not align when label text is larger than default

I cannot align Bootstrap v5 radio buttons vertically when the label is larger than the default text. For example, if the label is heading size 3, the radio button is at the top of the div.
<div class="form-check form-check-inline" id="btnColour" onchange="generateBtnCode()">
<input class="form-check-input" name="btnColour" id="btn-secondary" type="radio" value="secondary">
<label class="form-check-label" for="btn-secondary"><a class="btn btn-secondary">Secondary Grey</a></label>
</div>
Primary Bootstrap button as an input label
I have tried playing with vertical-align, line-height, margin-top, margin-bottom, toggling with all these things on the div, the input and the label. NOTHING WORKS.
https://codepen.io/madmanalphonsus/pen/JjBRELK - A codepen I've setup with a few different radio buttons. If anyone can figure this out I would be very appreciative.
Thanks
Tim
Adjusting the following in combination with the label/input/div:
Vertical align
Line Height
Margin
Padding
Justify-content
Screaming
Add these classes d-flex align-items-center to the div
<!-- Bootstrap CSS -->
<link rel="stylesheet" type="text/css" href="https://uq-itali.github.io/uqlearnx/medi7100/css/customStyles.css" />
<link rel="stylesheet" type="text/css" href="https://uq-itali.github.io/fontawesome-v6.1.1-free/css/all.css" />
<link rel="stylesheet" type="text/css" href="https://uq-itali.github.io/uqlearnx/medi7100/bootstrap-5.2.1-dist/css/bootstrap.css" />
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.js"></script>
<div class="d-flex align-items-center form-check form-check-inline" id="btnSize" onchange="generateBtnCode()">
<input class="form-check-input" name="btnSize" id="btnSize1" type="radio" value=" btn-sm">
<label class="btn btn-primary form-check-label fs-1 m-3" for="btnSize1">placeholder</label>
</div>
My goodness. I found the answer!
div.form-check-inline{
line-height: 1.5rem;
display: inline-flex;
}
label{
line-height: 1.5rem;
margin-left: 5px;
}
input[type='radio'] {
line-height: 1.5rem;
margin: auto;
}
So the trick is:
that the div incasing the input and radio button needs to be inline flex
all 3 elements (div, radio button, label) have to have the same line height.
The radio button margin: auto,
and the margin-left on the label is there to have a pocket of space between the label and input.
Then if you have an element inside the label. For example in my code builder I have a element inside the label, you have to remove the pre-existing margins for that element type. So with bootstrap add class="m-0" or inline styles style="margin: 0px;".
See my working codepen here - https://codepen.io/madmanalphonsus/pen/JjBRELK

Is there any function in selenium to input text in field which is not visible using java?

Enter text in ABSTRACT TILE filed using send keysI'm trying to input text in ABSTRACT_TITLE using send-keys in selenium.
I tried switching frames and giving input.
<div id="reTitleCenter" class="reContent" style="height: 2.91667em;" xpath="1">
<label for="reTitleContentHiddenTextarea" style="display:none;">RadEditor hidden textarea</label>
<textarea id="reTitleContentHiddenTextarea" name="ctl00$ctl00$ctl00$phDesktop$cphContent$cphContent$reTitle" rows="4" cols="20" style="display:none;"></textarea>
<iframe frameborder="0" src="javascript:'<html></html>';" id="reTitle_contentIframe" title="Rich text editor with ID reTitle" style="width: 100%; height: 100%; margin: 0px; padding: 0px;">Your browser does not support inline frames or is currently configured not to display inline frames.</iframe>
<textarea class="reTextArea reTextAreaHidden"></textarea>
</div>
the code samples I tried -
driver.switchTo().frame("reTitle");
driver.findElement(By.xpath("//div[#id='reTitleTop']/div[#class='RadEditor_Bootstrap reToolBarWrapper']")).click();
driver.findElement(By.xpath("//div[#id='reTitleTop']/div[#class='RadEditor_Bootstrap reToolBarWrapper']")).sendKeys("This is demo abstract");
OR
driver.switchTo().defaultContent();
WebElement Abstract_title = driver.findElement(By.xpath("//html//body"));
Abstract_title.sendKeys("This is abstract demo selenium");
OR
selenium.SelectFrame("xpath_of_iframe"); (Don't know how to use it)
selenium.Type("//html/body","Thank you");

Multi-line add-on for textarea

I'm using bootstrap 4 input-group and appending or pretending my inputs with add-ons as labels.
For the inputs its looking good. Now I need a multi-line add-on or label for text area.
I'm looking for best possible solution in Bootstrap or CSS.
Here is the code I'm trying.
<style>
.h-unset {
height: unset !important;
}
.multiline-label {
display: inline-block;
word-wrap: break-word;
word-break: break-word;
width: 100%;
}
</style>
<div class="input-group input-group-sm mb-3 row mx-0">
<div class="input-group-prepend col-md-3 px-0">
<label for="naastVastgoedbeleg-ging"
class="input-group-text w-100 rounded-0 multiline-label h-unset"
id="label-naastVastgoedbeleg-ging">
<strong>Werkzaamheden naast vastgoedbeleg-ging (bijv. loondienst of onderneming)</strong>
</label>
</div>
<textarea id="naastVastgoedbeleg-ging"
class="form-control rounded-0 col-md-9 h-unset"
aria-label="naastVastgoedbeleg-ging"
aria-describedby="label-naastVastgoedbeleg-ging">
</textarea>
</div>
Thankx for helping Happy Coding!
It worked by using this css
.multiline-label strong {
white-space: pre-wrap;
}

How can I access elements of a frame without a frame tag using Selenium Webdriver?

The concept of frames is being used on a website I am tasked with testing. However, the frames do not use frame tags, one is for example a div that is filled by GET/POST. Selenium cannot access the element inside of the frame (ElementNotVisibleException) because it must first switch to the frame. But, I can't switch to the frame because it is not technically a frame in Selenium's eyes. How can I access the content of the frame without manipulating the DOM? (The point of testing is that we test what is there as an end user and don't change it). So, I cannot use JavaScript executor. I have tried using action building to click elements/move to the element, but it returns errors.
EDIT:
Here is the basic form of the html I'm trying to access. I cannot use selenium to access any elements inside el1. I need to select an option for el6.
<div id="el1" style="width: 960px; height: 230px; margin-bottom: 6px;">
<div style="width: 955px;padding: 5px 0px 0px 5px;">
<span>Text Here</span>
<form id="el2" action="pageName.jsp?action=blah" method="POST" style="height: 300px;" name="el2">
<div id="el3" style="width: 600px; margin: 20px 0px 0px 60px;">
<div id="el4" style="height: 20px;">
<div id="el5" style="height: 20px; padding-left: 40px;">
<div style="width: 400px;">
<span style="font-weight: bold;">More Text Here</span>
</div>
<div style="width: 400px;">
<select id="el6" onchange="javascriptfunction(this)" name="el6" style="width: 400px;">
<option selected="selected" value="">A Select Box Option</option>
<option value="NumberHere">More Options Populated By JSP</option>
</select>
</div>
</div>
</div>
</div>
<!--Some Unnecessary content here-->
</form>
</div>
</div>
Here is style calculation for el6. I have tried manually adjusting height with WebDriver in attempt to get rid of ElementNotVisibleException. This did not work.
font-family MS Shell Dlg
body Helvetica,​Arial,​Sans-Serif
div Arial,​Helvetica,​Geneva,​sans-serif
body Arial,​Helvetica,​Geneva,​sans-serif
font-size 13.3333px
div 14px
body 13px
color rgb(0,​ 0,​ 0)
#container #333
text-align start
#wrapper left
.bodyStyle center
width 400px
margin-top 0px
margin-right 0px
margin-bottom 0px
margin-left 0px
padding-top 0px
padding-right 0px
padding-bottom 0px
padding-left 0px
why can't you switch to any available iframe without specifying the ID or name.
you can do this just switch to iframe..
try this
driver.switchTo().frame(driver.findElement(By.cssSelector("iframe")));
If you are getting ElementNotVisibleException,it means element is invisible at that time.You can use explicit wait to achieve this :
WebDriverWait wait = new WebDriverWait(driver,<Time>);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("el6")));
First,you calculate time which is taken by element to visible and replace with <Time>.
For more detail,you can [see][1].
[1]: http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp

How to bring browse button inside text box in html

** How to bring browse button inside text-box?
I have tried many solutions but I could not find.
Thanks-in-advance**
I had the same problem as you, if I understand it correctly.
You may want to use a javascript function to do so, or check the Mickael McGrady's solution :
http://www.quirksmode.org/dom/inputfile.html
Indeed, the display of your button/text-box depends on the version of your browser, so you may want to implement a relative button. On my website I did it in javascript which is more elegant, but if you prefer in html only :
<div class="fileinputs">
<input type="file" class="file" />
<div class="fakefile">
<input />
<img src="search.gif" />
</div>
</div>
and css :
div.fileinputs {
position: relative;
}
div.fakefile {
position: absolute;
top: 0px;
left: 0px;
z-index: 1;
}
input.file {
position: relative;
text-align: right;
-moz-opacity:0 ;
filter:alpha(opacity: 0);
opacity: 0;
z-index: 2;
}
<div class="fileinputs">
<input type="file" class="file" />
<div class="fakefile">
<input />
<img src="search.gif" />
</div>
</div>
(everything is detailled on the website since it's a well-known issue). Hope it helps.