Uploading a file with Selenium C# - c#

I'm having a problem managing File upload in Selenium using Chromedriver and C#. I read a couple of answers to similiar problems regarding the file uploader dialogue window and how this can be solved. The thing is that I don't have the standard input element but instead, I have this:
<div class="scUploadWrapper">
<div id="Overlay2" class="scUploadOverlay" style="width: 80px; height: 59px;">
<embed id="yuigen1" type="application/x-shockwave-flash" src="..." style="undefined" name="yuigen1" bgcolor="#ffffff" quality="high" allowscriptaccess="always" wmode="transparent" menu="false" flashvars="allowedDomain=domain.com&elementID=yuigen1&eventHandler=YAHOO.widget.FlashAdapter.eventHandler" tabindex="1" width="100%" height="100%"/>
</div>
<a class="scOption" href="#" onclick="javascript:scForm.invoke('media:multiupload(load=1, ownframe=1)');return false">
<img class="scIcon" src="/temp/IconCache/Applications/32x32/export1.png" alt="" width="32" border="0" height="32"/>
<div class="scHeader">Upload Files</div>
</a>
</div>
The thing is that this workaround
linkUploadFiles.WaitTillVisible();
linkUploadFiles.SendText(#"C:\Users\folder\image.PNG");
is therefore not usable. Any ideas what to do with it? I'm kinda stuck. Thanks a lot.

Selenium can not handle windows based dialogues. Instead use Auto IT scripts.
The example script is below.
Modify the script based on the properties of your windows dialogue:
Local $hWnd = WinWait("[CLASS:#32770]", "", 120)
ControlClick($hWnd,"","[CLASS:Edit; INSTANCE:1]")
Send($pathofFile)
Send("{ENTER}")
Exit

Related

How to select a value from Devextreme dropdown with Selenium C#

I need to select values (any value from House_TypeList) from dropdown menu with NUnit or just pure selenium. .
They are not seen in HTML.
I have tried select by xpath, by name, by span contains etc etc, I tried sending down key. I have waited for the element to become visible. I am out of ideas. Nothing works. I have not tried yet moving the cursor and trying to select it by that, but had a few problems implementing it and having in mind my luck, not really believing it will work either..
I am a beginner here, maybe I did some mistakes there. But I successfully managed any other inputs, buttons, navigation..
I have checked other similar questions, but could not find the answer that would work for me.
Is it even possible here?
Source:
<div class="dx-item dx-box-item" style="display: flex; min-height: auto; flex-grow: 1; flex-shrink: 1;"
<div class="dx-item-content dx-box-item-content" style="width: auto; height: auto; display: flex; flex-direction: column; flex-basis: 0px; flex-grow: 1;">
<div class="dx-first-col dx-last-col dx-field-item dx-field-item-required dx-col-0 dx-flex-layout dx-label-h-align">
<label class="dx-field-item-label dx-field-item-label-location-left" for="dx_dx-...._typeId">
<span class="dx-field-item-label-content" style="width: 159px;">
<span class="dx-field-item-label-text">Type:</span>
<span class="dx-field-item-required-mark"> *</span>
</span>
</label>
<div class="dx-field-item-content dx-field-item-content-location-right">
<div class="dx-textbox dx-texteditor dx-texteditor-empty dx-dropdowneditor-button-visible dx-widget dx-dropdowneditor-field-clickable dx-dropdowneditor dx-selectbox dx-validator dx-visibility-change-handler" id="slb_HouseManagement_EditHouse_TypeList">
<div class="dx-dropdowneditor-input-wrapper dx-selectbox-container">
<input type="hidden" value="" name="typeId">
<div class="dx-texteditor-container">
<input autocomplete="off" id="dx_dx-4e..._typeId" class="dx-texteditor-input" aria-haspopup="true" aria-autocomplete="list" type="text" readonly="" spellcheck="false" tabindex="0" aria-expanded="false" role="combobox" aria-required="true">
<div data-dx_placeholder="Select..." class="dx-placeholder"></div>
<div class="dx-texteditor-buttons-container">
<div class="dx-dropdowneditor-button dx-button-normal dx-widget" type="button">
<div class="dx-button-content">
<div class="dx-dropdowneditor-icon"></div>
</div></div></div></div></div></div></div></div></div></div>
Done. Found it in Devextreme support, the user had a bit different problem, but it solved mine as well.
IWebElement selectedItem = driver.FindElement(By.XPath("//div[#role='option']/div[text()='Apartment']"));
selectedItem.Click();
The DOM you have provided here does not contain any element for Lists. So I cannot share exact working code here. I will share few sample which you can update and use
With Selenium to select items from a list, you have two options to choose from:-
Select Class
Make an object of select class like below
Select obj =new Select(driver.findElement(By.id("search-box")));
Then you can use several functions on this select obj
obj.selectByVisibleText("Apartment");
Or
obj.selectByIndex(2);
or
obj.selectByValue("Farmhouse");
You can also get all the element in a List and then work around that list
List <WebElement> myHouseList = obj.getOptions();
System.out.println(myHouseList.size());
2.Actions Class
driver.manage().timeouts().implicitlyWait(10 , TimeUnit.SECONDS);
ele= driver.findElement(By.linkText("HouseList"));
Actions act = new Actions(driver);
act.moveToElement(ele).click();
WebElement webele = driver.findElement(By.linkText("Apartment"));
act.moveToElement(webele).click().build().perform();
Hope this helps you!!

Visual Studio collapsing html code

i have some html code as follows, which was supplied by our graphics developers. the issue is when i import this into asp.net (c#) page i get to see a lot of orphan divs. it feels as if there are not opening divs for several of the closing divs. following is code snippet.
<div class="col-lg-2 col-lg-3 quick-launch">
<div class="thumbnail">
<a href=""> <img src="assets/img/app_images/app_7.jpg" width="115" height="114">
<div class="caption">
<h3>TEST</h3>
</a></div>
</div>
</div>
could someone here please let me know if there is something in visual studio that is causing this?
You're inverting <div> and <a> closing tags. This is valid HTML (but not valid XHTML so you'd better to check your DOCTYPE) but it may confuse Visual Studio editor:
<a href=""> <img src="assets/img/app_images/app_7.jpg" width="115" height="114">
<div class="caption">
<h3>TEST</h3>
</a>
</div>
a
Should be:
<a href=""> <img src="assets/img/app_images/app_7.jpg" width="115" height="114">
<div class="caption">
<h3>TEST</h3>
</div>
</a>
Edit: what's wrong with that? It works because HTML parser doesn't complain about <a><div><a/></div> (if DOCTYPE isnt XHTML) but you should complain about it. Let me explain: parser won't complain because </div> (closing tag) isn't optional then it won't just silently add it. This is theory, in practice browsers handle this in many ways. Some of them silently close <div> when </a> is reached (then </div> will close outer one), some others don't do it (I repeat because it's not an optional closing tag) then </div> will close inner (and right) one. IMO With such unreliable behavior you should ask your developer/graphics designer to fix that code. In general (and with few exceptions like <hr> and <br>) I would write HTML code as it was XHTML.

How can I Insert an Umbraco Item in to a url in a cshtml file, razor?

I've made an If statement containing a youtube link.
In umbraco I have a Text String box that enables a user to insert the ID of a youtube video.
<div class="module m-video">
<div class="regular">
<div class="graphics video-container">
<iframe width="100%" src="http://www.youtube.com/embed/<umbraco:Item field="youtubeId" runat="server" />?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
But when the page loads it displays the <umbraco:Item field="youtubeId" runat="server" /> instead of what the user put in.
What work around is their to display what a user inserts into the text string box.
All must be done in razor
I would create a "YoutubeVideo" macro along with it's razor script "YoutubeVideo.cshtml". And that cshtml code would look like this:
#using umbraco.MacroEngines
#inherits umbraco.MacroEngines.DynamicNodeContext
<div class="module m-video">
<div class="regular">
<div class="graphics video-container">
<iframe width="100%" src="http://www.youtube.com/embed/#Model.youtubeId?rel=0" frameborder="0" allowfullscreen></iframe>
</div>
</div>
</div>
Then in your .master you could include that mascroscript like this:
<umbraco:Macro ID="Macro1" Alias="YoutubeVideo" runat="server" />
This approach may differ if you are using Umbraco 6+ with MVC, but otherwise this should do the trick.
If you are doing this inside the umbraco template editor you should be able to swap the double quotes denoting the src attribute with single quotation marks, and the umbraco item needs no change.
<iframe width="100%" src='http://www.youtube.com/embed/<umbraco:Item field="youtubeId" runat="server" />?rel=0' frameborder="0" allowfullscreen></iframe>

Why my image slider not working on other pages in a subfolder using masterpage

Hi been creating a web application using VS 2010 using C#.the problem i am having is that i have added image slider on the master page. but when i run the application it does not show the slider on the pages which are in a subfolder but shows the image slider in a file which is in the root.
for the image slider i have used jquery
this is how i have coded the images on masterpage
<div id="slide-holder">
<div id="slide-runner">
<img id="slide-img-1" src="~/Styles/images/nature-photo1.png" class="slide" alt="" />
<img id="slide-img-2" src="~/Styles/images/nature-photo1.png" class="slide" alt="" />
<img id="slide-img-3" src="~/Styles/images/nature-photo2.png" class="slide" alt="" />
<img id="slide-img-4" src="~/Styles/images/nature-photo3.png" class="slide" alt="" />
<img id="slide-img-5" src="~/Styles/images/nature-photo4.png" class="slide" alt="" />
<img id="slide-img-6" src="~/Styles/images/nature-photo4.png" class="slide" alt="" />
<img id="slide-img-7" src="~/Styles/images/nature-photo6.png" class="slide" alt="" />
<div id="slide-controls">
<p id="slide-client" class="text"><strong>post: </strong><span></span></p>
<p id="slide-desc" class="text"></p>
<p id="slide-nav"></p>
</div>
</div>
it not showing up on the pages located in subfolders but working with pages located in the root
You have to make sure that all of the src and urls are being resolved successfully. For this, use the ResolveUrl() function to successfully resolve all of your images regardless of the location. Also, if you are using Css, you have to make sure the images inside the css are being resolved correctly:
Example:
<img id="slide-img-2" src='<%= ResolveUrl("~/Styles/images/nature-photo1.png") %>' class="slide" alt="" />
Good luck!

Bind control to JavaScript file

I had JavaScript slide show which had Image and text .But I want to mange js code to retrieve it's data(image, text) from database by code .please anyone help more it more difficult.
aspx page:
<form id="form1" runat="server">
<div class="hom_scrooler_con tm10 "><script type="text/javascript" src="js/scroller.js"></script>
<div class="hom_but_a "><img src="images/home-bu_pro.jpg" alt="#" name="Image9" width="134" height="34" border="0" id="Image9" /></div>
<div class="hom_but_a"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image8','','images/home-bu_news.jpg',1)"><img src="images/home-bu_npro.jpg" alt="#" name="Image8" width="134" height="34" border="0" id="Image8" /></div>
<div class="hom_but_a"><img src="images/home-bu_news.jpg" width="134" height="34" border="0" /></div>
</div>
</form>
JS:
sts_bs("jwscroller2dbd",[20080623,"images/","","blank.gif",0,1,0,50,"50%","left",2,3,298,199,1,10,0,0,0,2000,1,12,2,
"stEffect(\"scroll(Rate=24,enabled=0,Duration=0.50)\")",-2,60],["none",1,"#454545","transparent","","no-repeat"]);
sts_sca(["center","middle","center","middle"],["aro-lft.png","aro-lftr.png","arrowl_gray.gif",56,55,"aro-rt.png","aro-rtr.png","arrowr_gray.gif",55,51]);
sts_tbd([1],["solid",1,"#454545",5,"round_tl.gif","round_tr.gif","round_br.gif","round_bl.gif","transparent","round_t.gif",
"repeat","transparent","round_r.gif","repeat","transparent","round_b.gif","repeat","transparent","round_l.gif","repeat"]);
sts_ai("i0",[0,"New Sharp Copiers Now 2\r\n\r\nHas been the industry\'s standard dummy text ever
when an unknown printer.Simply dummy text of","#","_self","media3_07.png",298,197,"left"],["transparent"
,"bold 10pt Verdana,Arial","#666666","none","bold 10pt Verdana,Arial","#666666","none"]);
sts_ai("i1",[,"New Sharp Copiers \r\n\r\nHas been the industry\'s standard dummy text ever when an unknown printer.Simply
dummy text of",,,"media3_08.png"],[,,,,"italic bold 10pt Verdana,Arial"],"i0","i0");
sts_es();
Don't use JavaScript to connecto to a database. If you want to get data from a database, use jQuery and AJAX to get data from a .Net Web Service. It's pretty simple, and reusable.
You can build your own AJAX controls without jQuery, but I wouldn't...

Categories