I'm very new to VBScript or any scripting for that matter.
I want the script to check whether an image is loaded. Below is the script up to the point of where I'm stuck.
strURL="https://www.Test.com/"
strUser="******"
strPass="******"
Set oIE = WScript.CreateObject("InternetExplorer.Application","IE_")
Timeout=20 'seconds
oIE.visible=1 : BeginTimer = Timer
oIE.Navigate strURL
i=0 : bElementsLoaded=false
Set CODA_Element_1 = Nothing
Do While (oIE.ReadyState<>4 Or Not(bElementsLoaded)) And i < Timeout
WScript.Sleep(1000):i=i+1
On Error Resume Next
Set CODA_Element_1 = oIE.Document.getElementById("user")
Set CODA_Element_2 = oIE.Document.getElementById("password")
Set CODA_Element_3 = oIE.Document.getElementById("next")
If (Not(CODA_Element_1 is Nothing)) Then
bElementsLoaded=true
End If
On Error Goto 0
Loop
CODA_Element_1.value=strUser
CODA_Element_2.value=strPass
CODA_Element_3.Click()
From here on in i have no idea.... The image i want to check is loaded is /codaprod/images/portal.jpg
In the below snippet of source code
<DIV id="esisplitpanelower" class="scroller" style="height:100%; overflow:auto">
<TABLE cellpadding=0 cellspacing=0 height="100%" width="100%">
<TR><TD width="100%" height="100%"><TABLE cellpadding=0 cellspacing=0 height="100%" width="100%">
<TR><TD align="center" valign="top" width="100%" height="100%"><TABLE cellpadding=0 cellspacing=3 align="center" valign="top" height="100%" width="100%">
<TR><TD align="center" width="100%" height="100%"><TABLE cellpadding=0 cellspacing=3 align="center" height="100%" width="100%">
<TR><TD align="center"><IMG src="/codaprod/images/portal.jpg" title="Home Page">
</TD>
</TR></TABLE>
</TD>
</TR></TABLE>
</TD>
</TR></TABLE>
</TD>
</TR></TABLE>
</DIV>
Can somebody please show me how to check if this image is loaded? If loaded display msgbox "Working!" and if the image is not loaded then msgbox "Not Working!"
One way is to use <img>'s onload() method.
<script type="text/vbscript">
sub loadImage()
msgbox "Image is loaded"
end sub
</script>
<img src="anyold.gif" onload="loadImage">
W3Schools gives a JavaScript version of that same thing: http://www.w3schools.com/jsref/event_img_onload.asp
You can check using the image object's complete property
http://www.w3schools.com/jsref/prop_img_complete.asp
Here's an example:
For Each pix In oIE.document.images
Do Until pix.complete=true
WScript.Sleep 10
Loop
Next
You need to tailor this to your precise image, possibly comparing the image object's src property for checking the precise image you want to know if it is loaded or not.
Related
I try to write an outlook plugin that inserts a link into the email body. I want to give the link a style in order to look as a button, to give the user a more engaging experience.
The issue I got, is that outlook changes the style on the elements, and the inline style I put on that element is getting lost.
I am inserting the HTML as shown below:
var tablePref = '<table align="left" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse;margin: 0;"><tr><td border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse;margin: 0;padding: 10px 18px;background:\'';
var backgroundColor = 'green'; //The color is user-given, I put green as an example
var tableSuf = '\'">Some text</td></tr></table>'
var item = Office.context.mailbox.item;
item.body.setAsync(tablePref+backgroundColor+tableSuf,
{
coercionType: Office.CoercionType.Html,
asyncContext: {}
},
function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Failed)
{
//Show error dialog
}
else
{
//Successfully set data in item body.
}
});
I get the link on the email successfully, and it looks just right, but when I send the email, the HTML structure of this button looks like this instead:
<table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" align="left" style="border-collapse: collapse">
<tbody>
<tr>
<td style="background: 'green';">
<p class="MsoNormal" style="mso-element: frame; mso-element-frame-hspace: 2.25pt; mso-element-wrap: around; mso-element-anchor-vertical: paragraph; mso-element-anchor-horizontal: column; mso-height-rule: exactly">
<a href="https://somelink.com" target="_blank" rel="noreferrer">
<span style="text-decoration: none">Some Text</span>
</a>
<!-- o ignored -->
</p>
</td>
</tr>
</tbody>
</table>
Outlook is changing my a elements, and this causes that mail clients render the element with a line below because the style got overridden. Is there any way to avoid Outlook change my HTML or it is a known bug? This is happening across all platforms (OWA, Outlook for Mac 16.21 and Outlook for Windows)
Thanks for any help
Below is the tag from which i want to click an image file which will navigate to another link in a web browser (IE), [I tried using the destination link, but due to the limitation i am not able to paste the direct URL]
Below the WEb tag
<td class="Btext4" align="center" style="border-top-style: none">
<img onclick="appSubmit('/Web/portlets/applications/redirect.jsp?PARAM=26','26','_blank')" class="applinklnh" src="/ABCD/Content/images/launch_4_june.gif" alt="Launch IPMS" width="94" height="36" border="0" style="cursor:pointer;">
</td>
<td class="Btext4" align="center" style="border-top-style: none">
<img onclick="appSubmit('/Web/portlets/applications/redirect.jsp?PARAM=26','26','_blank')" class="applinklnh" src="/ABCD/Content/images/launch_4_june.gif" alt="Launch TGIF" width="94" height="36" border="0" style="cursor:pointer;">
</td>
*Edited : Tags added to get a clear id on where i am stuck
Till not i am able to code this much, and many attempts later I am not able to move ahead
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
CreateObject("WScript.Shell").AppActivate "Internet Explorer"
objIE.Navigate "https://www.website.net/"
While objIE.Busy
if x = vbNo then
WScript.Sleep 100000000
Else
WScript.Sleep 10
End if
Wend
objIE.Document.getElementById("USER").value = "username"
objIE.Document.getElementById("PASSWORD").value = "password"
objIE.Document.getElementById("login_button").click
While objIE.Busy
WScript.Sleep 100
Wend
Please help me where i am doing things wrong. THanks
Selenium is not able to find elements.
I am trying to find an id with PageHeader_logourl
But it's throwing Unable to locate an element with xpath expression.
Am I doing anything wrong
Here is the html code
<DIV id="page" class="page">
<DIV id="wrapper" class="wrapper">
<DIV id="header" class="header">
<TABLE width="100%" height="40" cellspacing="0" cellpadding="0" border="0" ID="Table2">
<TR>
<TD>
<TABLE height="40" cellspacing="0" cellpadding="0" border="0" ID="Table3">
<TR>
<TD><span id="HeaderLogoImage"></span></TD>
<TD valign="middle"><label id="PageHeader_lblProjectName" class="projectname">Scania Trucks – SSS 4 TestR1</label></TD>
Here is the snapshot of my selenium code:
driver.findElement(By.xpath("//input[#name='UserNameInputText']")).sendKeys(username);
driver.findElement(By.xpath("//input[#name='Brand']")).sendKeys(password);
driver.findElement(By.xpath("//input[#name='CmdLogin']")).click();
Assert.assertTrue(isuserloggedin(),"Login failed");
}
public boolean isuserloggedin()
{
boolean flag = false;
if (!driver.findElements(By.id("Cancel")).isEmpty() ||
driver.findElement(By.xpath("//a[#id=['PageHeader_logoUrl']")).isDisplayed());
{
flag = true;
}
return flag;
There seems to be an error of one extra [ in your xpath. You may want to try this "//*[#id='PageHeader_logoUrl']"
You can look for more strategies here
Try search the parent element first:
by.Xpath("//table[#id='Table3']//a[#id='PageHeader_logoUrl']")
Also my suggestion (again) is to search the nearest/ parent element first and debug if you actually get the element that you wanted.
I need to test if a recordset has a next element before actually moving to it with
Recordset.MoveNext
EDIT:
I have some records, which are separated with an image but when it comes to the last record there is no need for the image that why I need to test if the record has a next one or it is the last one
<% while not Recordset.EOF
ItemId = Recordset.fields("ITEM_ID")
itemView= ItemId &" "& Recordset.fields("SHORT_DESC")
%>
<tr>
<td style="width:240px !important; word-break: break-all;">
<a href="view_work_item.asp?item_id=<%=ItemId%>&hometoURL=<% =Server.URLEncode(navpath & "/de/ticket/liste_ticket_pl.asp")%>" >
<%=titemView%></a></td>
<td background="../../images/white-dot.gif" ><img src="../../images/white-dot.gif" width="1" height="8" ></td>
<td style="width:240px !important; word-break: break-all;"><%=i%></td>
</tr>
//test here if it's the last element don't show this image
<tr>
<td align="center" class="subnav" colspan="3" height="1"><img src="../../images/white-dot.gif" width="100%" height="1"/></td>
</tr>
<% Recordset.MoveNext
wend %>
Use Recordset.EOF or BOF for begining
if not Recordset.EOF then
Recordset.MoveNext
end
To solve you problem try this.
<% while not Recordset.EOF
ItemId = Recordset.fields("ITEM_ID")
itemView= ItemId &" "& Recordset.fields("SHORT_DESC")
Recordset.MoveNext
%>
<tr>
<td style="width:240px !important; word-break: break-all;">
<a href="view_work_item.asp?item_id=<%=ItemId%>&hometoURL=<% =Server.URLEncode(navpath & "/de/ticket/liste_ticket_pl.asp")%>" >
<%=titemView%></a></td>
<td background="../../images/white-dot.gif" ><img src="../../images/white-dot.gif" width="1" height="8" ></td>
<td style="width:240px !important; word-break: break-all;"><%=i%></td>
</tr>
<% if not Recordset.EOF then %>
//test here if it's the last element don't show this image
<%end%>
<tr>
<td align="center" class="subnav" colspan="3" height="1"><img src="../../images/white-dot.gif" width="100%" height="1"/></td>
</tr>
<% wend %>
You could move your Recordset.MoveNext statement before your HTML and test it there. You've already saved the recordset values you need so advancing it early won't change anything. And I would think this would work better if you only have a single record, too, since it won't display the image delimiter.
If Not Recordset.EOF Then
Do While True
ItemId = Recordset.fields("ITEM_ID")
itemView= ItemId &" "& Recordset.fields("SHORT_DESC")
Recordset.MoveNext
If Recordset.EOF Then Exit Do
' HTML code here
Loop
End If
Here is the issue: I would like a white border on the picture, but when I send it to my outlook 2007 or 2010, it's not showing. Here is the code for the image in question:
<img src="my.jpg" alt="" width="220" height="220" border="3" style="border:3px solid #FFF;" />
Is there a fix out there for this issue? I feel like I've tried everything and nothing's worked.
This did render a border, but it's not an ideal solution because there is a space between the image and border.
<table width="220" height="220" border="0" cellspacing="0" cellpadding="0" style="border:3px solid #FFF;">
<tr>
<td>
<img src="my.jpg" alt="" width="220" height="220" border="0" title="70's Styled House and Pool" />
</td>
</tr>
</table>
I think you will have to wrap it in something. How about Span:
s = "<html><body>" _
& "<span style='display:inline-block;padding:5px;border:5px solid #fff;'>" _
& "<img src='z:\docs\image1.jpg' alt='' width=220 height=220></span>" _
& "</body></html> "
Set oEmail = Application.CreateItem(olMailItem)
oEmail.HTMLBody = s
oEmail.Display
I couldn't get the SPAN solution to work (I suspect because of extra code added by my CMS).
My solution was to wrap the image in a table with cellpadding set to the desired border width, and bgcolor set to the desired border colour. Hardly semantic, but that's Outlook's fault.
One of your issues is that hex color short-hand isn't supported in email. So you should be using all six hex digits.
<img
src="http://example.com/image.jpg"
alt=""
width="220"
height="220"
border="3"
style="border:3px solid #ffffff;" />