Anyone know how to select the specific element that contain in the attachment to download as i can't able to select the respective attachment. the screenshot I have put in the below :
below is the html code for the specific container
<div class="attachment-wrap">
<!-- Comment Title -->
<div id="attachmentTitle-wrapTEST" class="attachmentTitle-wrap">
<h2>Attachments</h2>
</div>
<div id="attachment-containerTEST">
<!-- Attachment Box -->
<div class="comment-box">
<!-- Comment Image -->
<div class="col-xs-2">
<div class="attachmentImg">
<img src="downloadAttachment?attachmenturl=/secure/thumbnail/10104/_thumb_10104.png" />
</div>
</div>
<!-- Attachment details -->
<div class="col-xs-10">
<div class="commentContent">
<div class="topRow">
<div class="username">1177A149.PNG</div>
<div class="commentTimeStamp">25927 KB</div>
</div>
<div class="bottomRow">
<div class="commentDisplay">
Download
</div>
</div>
</div>
</div>
</div>
<div class="comment-box">
<!-- Comment Image -->
<div class="col-xs-2">
<div class="attachmentImg">
<img src="downloadAttachment?attachmenturl=/secure/thumbnail/10103/_thumb_10103.png" />
</div>
</div>
<!-- Attachment details -->
<div class="col-xs-10">
<div class="commentContent">
<div class="topRow">
<div class="username">4D7746B6.PNG</div>
<div class="commentTimeStamp">62766 KB</div>
</div>
<div class="bottomRow">
<div class="commentDisplay">
Download
</div>
</div>
</div>
</div>
</div>
Appreciate if you can help me with this.
You can do it in the below way to click the respective download link based on the attachment name
Code:
//Expected attachment filename needs to be specified here.
var expectedFileName = "1177A149.PNG";
//This list will hold all the available attachment section details
IList<IWebElement> attachmentList = _driver.FindElements(By.ClassName("comment-box"));
foreach(var element in attachmentList)
{
var attachmentFilename = element.FindElement(By.XPath(".//div[#class='username']")).Text;
if(attachmentFilename == expectedFileName)
{
//If the actual file name and expected file name matches, then corresponding download link will be clicked
element.FindElement(By.XPath(".//a")).Click();
break;
}
}
You an create xpath specific to png name. see here
//a[contains(#href,'downloadAttachment?filename=4D7746B6.PNG')]
It will point to download link having filename=4D7746B6.PNG
Related
Dear friends I am currently creating an admin panel for user where they can easily can publish their articles. I also want to add to my form a little fileuploader but sadly I got some problems with DROPZONEJS.JS file in POST method. The main problem is I cannot give URL to project's local file in order to download to file there where website will access those file in order to publish them with current article's id. Please let me know if there is something not understandable.
#{
ViewBag.Title = "Uppy";
}
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
<!--begin::Entry-->
<div class="d-flex flex-column-fluid">
<!--begin::Container-->
<div class="container">
<!--begin::Card-->
<div class="card card-custom gutter-b">
<div class="card-header">
<div class="card-title">
<h3 class="card-label">File Upload</h3>
</div>
</div>
<!--begin::Form-->
<form>
<div class="card-body">
<div class="form-group row">
<label class="col-form-label col-lg-3 col-sm-12 text-lg-right">Multiple File Upload</label>
<div class="col-lg-4 col-md-9 col-sm-12">
<div class="dropzone dropzone-default dropzone-primary" id="kt_dropzone_2">
<div class="dropzone-msg dz-message needsclick">
<h3 class="dropzone-msg-title">Drop files here or click to upload.</h3>
<span class="dropzone-msg-desc">Upload up to 10 files</span>
</div>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-form-label col-lg-3 col-sm-12 text-lg-right">File Type Validation</label>
<div class="col-lg-4 col-md-9 col-sm-12">
<div class="dropzone dropzone-default dropzone-success" id="kt_dropzone_3">
<div class="dropzone-msg dz-message needsclick">
<h3 class="dropzone-msg-title">Drop files here or click to upload.</h3>
<span class="dropzone-msg-desc">Only image, pdf and psd files are allowed for upload</span>
</div>
</div>
</div>
</div>
</div>
#using (Html.BeginForm("Uppy",
"FileUpload",
FormMethod.Post,
new { enctype = "multipart/form-data" })) //multipart/form-data gives functionlity to inputes (search at web);
{
<div class="card-footer">
<div class="row">
<div class="col-lg-3"></div>
<div class="col-lg-4">
<input type="submit" value="Submit" class="btn btn-light-primary mr-2" />
<button type="reset" class="btn btn-primary">Cancel</button>
</div>
</div>
</div>
}
</form>
<!--end::Form-->
</div>
<!--end::Card-->
<!--end::Row-->
</div>
<!--end::Container-->
</div>
<!--end::Entry-->
</div>
<!--end::Content-->
By the way my own upload code is working correctly and also sends choosen file to url location where I wrote in controller.
<label for="file">Upload File:</label>
<input type="file" name="file" id="file" class="btn-hover-bg-success" />
<br>
<br>
<input type="submit" value="Upload Image" />
<br>
<br>
#ViewBag.Message
This is my FileUploadController:
[HttpPost]
public ActionResult Uppy(HttpPostedFileBase file)
{
ADAPTIVE_TESTEntities ent = new ADAPTIVE_TESTEntities();
Adaptive.News.Models.NEWS news = new Adaptive.News.Models.NEWS();
if (file != null && file.ContentLength > 0)
try
{
var path = Path.Combine(Server.MapPath("~/Content/images"),
Path.GetFileName(file.FileName));
file.SaveAs(path);
news.PICTUREPATH = path;
ent.NEWS.Add(news);
ent.SaveChanges();
ViewBag.Message = "File uploaded successfully";
}
catch (Exception ex)
{
ViewBag.Message = "ERROR: " + ex.Message.ToString();
}
else
{
ViewBag.Message = "You have not specified a file.";
}
return View();
}
it is not obvious to me, what and where really your problem is. What do you mean with having problem. Is your problem with Dropzone.JS or with C#? Anyway, I examined your code slightly and have some ideas what your problem could be.
FIRST OF ALL: You have 2 DIV containers, which you use as Dropzone elements assigning them the css class "dropzone". Furthermore you generate a FORM element with ASP.Net HTML-Helper.
By default you have 2 options using Dropzone.
Declarative instantiation via assigning css class "dropzone" to any HTML element.
Dropzone discovers all DOM elements with class="dropzone" automatically and instantiates them.
Programmatically instantiating: You instantiate Dropzone by passing the id of the container element and THE OPTIONS CONTAINING POST URL to the Dropzone constructor.
DECLARATIVE DROPZONE
You must pay attention to this detail: If you use FORM element as Dropzone container element, Dropzone uses "action" attribute of the FORM element as post URL. But if you use
DIV element as container, then you get most possibly a JavaScript error. Because DIV elements do usually NOT have "action" attribute. If you use DIV as Dropzone container (and in your code you use it 2 times), you will get following JavaScript error:
dropzone.js:1027 Uncaught Error: No URL provided.
at new Dropzone (dropzone.js:1027)
at dropzone.js:2907
at Function.Dropzone.discover (dropzone.js:2919)
at Dropzone._autoDiscoverFunction (dropzone.js:3491)
at HTMLDocument.init (dropzone.js:3456)
In this case you have two options solve the problem:
Use FORM element instead of DIV as Dropzone container.
Add action="/your/post/url" to your DIV element, which you use as Dropzone container.
Where I would prefer the first option. Because it is not common that DIV elements have action attribute.
I use geckofx in my project c#, how can I get all the output :
Text 1
Text 2
Text 3
if the code example is like this :
<div class="A">
<div class="B">
<div class="C">
<div class="D">Text 1</div>
</div>
<div class="C">
<div class="D">Text 2</div>
</div>
<div class="C">
<div class="D">Text 3</div>
</div>
</div>
</div>
How about:
var a = this.Document.GetElementsByClassName("A").FirstOrDefault(); //this returns the parent A div (if it exists)
if (a != null)
{
var text = a.TextContent; // and that gets the full text.
}
Please bear in mind that 'GetElementsByClassName' returns a collection, because there can be many elements with the same class.
Anyone know how to print out all the elements that contain in a list with text value in selenium c#? Try to do like the code below it print out blank value. But if i were to put writeline with elem only the value was display but it is not in text form. I would like to get value with text.
Code:
IList<IWebElement> attachmentList = driver.FindElements(By.ClassName("comment-box"));
foreach (IWebElement element in attachmentList)
{
Console.WriteLine(element.Text);
}
HTML:
<div class="comment-box">
<!-- Comment Image -->
<div class="col-xs-2">
<div id="attachmentImgSFHD-24" class="attachmentImg">
<img src="downloadAttachment?attachmenturl=/secure/thumbnail/10111/_thumb_10111.png" />
</div>
</div>
<!-- Attachment details -->
<div class="col-xs-10">
<div class="commentContent">
<div class="topRow">
<div class="username">ApplicationLink.png</div>
<div class="commentTimeStamp">31400 KB</div>
</div>
<div class="bottomRow">
<div class="commentDisplay">
Download
</div>
</div>
</div>
</div>
</div>
<div class="comment-box">
<!-- Comment Image -->
<div class="col-xs-2">
<div id="attachmentImgSFHD-24" class="attachmentImg">
<img src="downloadAttachment?attachmenturl=/secure/thumbnail/10313/_thumb_10313.png" />
</div>
</div>
<!-- Attachment details -->
<div class="col-xs-10">
<div class="commentContent">
<div class="topRow">
<div class="username">test.jpg</div>
<div class="commentTimeStamp">7423 KB</div>
</div>
<div class="bottomRow">
<div class="commentDisplay">
Download
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br/>
The elements don't have text in the html, so element.Text is empty. Use
Console.WriteLine(element.GetAttribute("value"));
You can use the below Xpath to get the attachment details
Xpath: //div[#class='comment-box']//div[#class='commentContent']//div[#class='username']
Code:
IList<IWebElement> attachmentList = driver.FindElements(By.XPath("//div[#class='comment-box']//div[#class='commentContent']//div[#class='username']"));
foreach (IWebElement element in attachmentList)
{
Console.WriteLine(element.Text);//It will print all the attachment name like 'ApplicationLink.png,test.jpg'
}
IList<IWebElement> attachmentList = driver.FindElements(By.ClassName("comment-box"));
foreach (IWebElement element in attachmentList)
{
System.Threading.Thread.Sleep(2000);
Console.WriteLine(element.Text);
}
it works fine by putting the thread.sleep code
i have a grid view to show my blog posts, my posts are in video,image,text format and each has html template that is different with another:
html:
<!-- Image Format -->
<div class="post format-image box">
<div class="frame">
<a href="post.html">
<img src="Templates/images/art/post1.jpg" alt="" />
</a>
</div>
<h2 class="title">Morning Glory</h2>
<p>text</p>
<div class="details">
<span class="icon-image">September 26, 2012</span>
<span class="likes">44</span>
<span class="comments">3</span>
</div>
</div>
<!-- Video Format -->
<div class="post format-video box">
<div class="video frame">
<iframe src="http://player.vimeo.com/video/40558553?title=0&byline=0&portrait=0" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
</div>
<h2 class="title">Fragments of Iceland</h2>
<p>text</p>
<div class="details">
<span class="icon-video">September 13, 2012</span>
<span class="likes">18</span>
<span class="comments">1</span>
</div>
</div>
<!-- Text Format -->
<div class="post format-standard box">
<h2 class="title">The Meridian Sun</h2>
<p>text</p>
<p>text</p>
<div class="details">
<span class="icon-standard">August 13, 2012</span>
<span class="likes">11</span>
<span class="comments">0</span>
</div>
</div>
as you know if i want to have list of my posts in usually way
i should add grid view with item template and set my template in it,
but as you see i have 3 templates for my records,
and i have a field in my table called 'PostMode' that accepts 3 string :
Video, Image, Text.
now my question is how can i use 3 templates in item template that if my record was
Video display video template and if it was Text display Text format in my blogs list.
TemplateField tF = new TemplateField();
// tF.HeaderText = dr["COLUMN_NAME"].ToString();
tF.HeaderText = col.ToString();
tF.ItemTemplate = LoadTemplate("~/xxxxxxx.ascx");
grdVw.Columns.Add(tF);
Sorry for posting in such a hurry ,
Hope it helps .
My labels: The labels are mentioned here followed by the code.
<div id="valueIntroduction" class="labelarea" runat="server"> </div>
<div class="line"></div>
<div id="valueBacklog notice" class="labelarea"> </div>
<div class="line"></div>
<div id="valueReasonably complete" class="labelarea"> </div>
<div class="line"></div>
<div id="valueStatement of purpose" class="labelarea"> </div>
<div class="line"></div>
<div id="valueResume" class="labelarea"> </div>
<div class="line"></div>
<div id="valueTranscripts" class="labelarea"> </div>
<div class="line"></div>
<div id="valueGRE Official test scores" class="labelarea"> </div>
<div class="line"></div>
<div id="valueTOEFL or IELTS Official test scores" class="labelarea"> </div>
<div class="line"></div>
<div id="valueLetters of Recommendation3" class="labelarea"> </div>
<div class="line"></div>
<div id="valueLetters of Recommendation2" class="labelarea"> </div>
<div class="line"></div>
<div id="valueLetters of Recommendation1" class="labelarea"> </div>
<div class="line"></div>
<div id="valueSignature" class="labelarea"> </div>
<div class="line"></div>
<div id="valueSubject" class="labelarea"> </div>
<div class="line"></div>
This code is assigning the last record to the first label. How do I assign the correct record to correct label?
if (Department.Items[0].Selected)
{
firstPanel.Visible = true;
myLegend.InnerText = "Informatics";
NewComm.CommandText = "getTextHeaderINFO";
NewComm.CommandType = CommandType.StoredProcedure;
NewComm.Connection = NewConn;
NewComm.CommandTimeout = 3000;
SqlDataReader results = NewComm.ExecuteReader();
while (results.Read())
{
Response.Write(results["TEXT_CONTENT"].ToString());
valueIntroduction.InnerHtml = results["TEXT_CONTENT"].ToString();
}
}
Well, as it is written now you are setting the same label's InnerHtml in every iteration of the while loop.
I would think you would be doing something more like this:
label1.InnerHTML = results["text_content"];
results.read()
label2.InnerHtml = results["text_content"];
etc.
In short, you'll need to assign the results iteratively. It may be safer to read them into a List or a string array (in your loop) so you can verify count, but essentially you have to set each label individually. I can't image how you could expect it to work setting a single one over and over again.
Now, what you SHOULD be doing, when you intend to work with HTML elements programmatically is very different from what I see here.
What you're doing here requires you to lookup HTML elements by ID, assign to their InnerHtml, and is honestly very error-prone. It's also not a good use of C# or the .NET environment.
Use .NET labels instead. Define them like this:
<asp:Label runat="server" id="valueIntroduction" CssClass="labelarea" />
Then on the code behind you can access them much easier:
valueIntroduction.Text = "This text will show up in the valueIntroduction label";
Why do you call results.Read() in a loop? You should just find the one single result row in the results and put this one into the valueIntroduction.InnerHtml property.