Selenium and eCharts - Struggling to parse text showed as a popup - c#

Hi am trying to parse text that appears as a popup when hovering on elements in a given eChart. I can see the text I am looking for in the HTML.
I'm using Selenium and C#.
I tried all the methods and combinations but Selenium usually retrieves an IWebElement without text.
This is the piece of html in the page I'm parsing:
<div style="position: absolute; display: none; border-style: solid; white-space: nowrap; z-index: 9999999; transition: left 0.4s cubic-bezier(0.23, 1, 0.32, 1) 0s, top 0.4s cubic-bezier(0.23, 1, 0.32, 1) 0s; background-color: rgb(34, 34, 34); border-width: 0px; border-color: rgb(51, 51, 51); border-radius: 4px; color: rgb(255, 255, 255); font: 14px / 21px "Microsoft YaHei"; padding: 10px; left: -63px; top: -15px; pointer-events: none;">Failures: 2<br>Execution Date: 2020-07-16 17:28</div>
I'm trying to parse the "Failures: 2" and "Execution Date: 2020-07-16 17:28" strings
I tried the following commands:
var hover1 = _driver.FindElement(By.XPath("//div style[text() = 'Failures: 2']"));
var hover1 = _driver.FindElement(By.XPath("//*[contains(., 'Failures:')]"));
I will appreciate any help.

Related

Managing Session's for Direct line channel web widget

I have a bot which is on a web widget, i will have this bot integrated to a parent application, from which i am fetching user's employee code. I want to handle the use case in which if a user is already talking to my bot i.e already in a session , then user cannot open another window from any other system or browser and talk at the same time. I want to map user's employee code in a way that if the above scenario happens my bot informs the user that you are already in session.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Digital Assistant</title>
<link href="https://cdn.botframework.com/botframework-webchat/latest/botchat.css" rel="stylesheet" />
<style>
.example {
float: left;
margin-right: 20px;
width: 300px;
}
.example > h2 {
font-family: 'Segoe UI';
}
#BotChatGoesHere {
border: 1px solid #333;
right: 10px;
height: 100%;
position: absolute;
width: 100%;
bottom:10px;
}
.wc-header {
background-color: #107ad1;
box-shadow: 0 1px rgba(0, 0, 0, 0.2);
box-sizing: content-box;
color: #ffffff;
font-weight: 500;
height: 40px;
left: 0;
letter-spacing: 0.5px;
padding: 8px 8px 0 8px;
position: absolute;
right: 0;
top: 0;
z-index: 1;
background-image: url(https://example.com/ess/App_Themes/HomepageBlue/images/tab_bg.jpg);
}
.wc-header span{
text-shadow: 1px 1px 2px black, 0 0 1em blue, 0 0 0.2em darkblue;
font-size: 24px;
padding: 0 15px;
}
.wc-time {
color: #999999;
margin-bottom: 10px; }
.wc-message-groups {
bottom: 50px;
left: 0;
transform: translateY(0);
outline: 0;
overflow-x: hidden;
overflow-y: scroll;
padding: 10px;
position: absolute;
right: 0;
top: 38px;
transition: transform 0.2s cubic-bezier(0, 0, 0.5, 1);
background:linear-gradient(64deg,#1c627d 0,#1c637e 11%,#1b677f 20%,#196c81 27.5%,#177283 33.7%,#157986 38.8%,#138089 43.3%,#10888c 47.3%,#0e918f 51.2%,#0c9892 55.3%,#09a095 59.9%,#07a798 65.2%,#06ad9a 71.6%,#04b19b 79.3%,#03b49d 88.7%,#03b59d 100%);
}
.wc-message-groups.no-header {
top: 0; }
.wc-videocall-image{
cursor: pointer;
float: right;
width: 30px;
height: 30px;
margin-right: 12px;
border-radius: 50%;
font-size: 18px;
text-align: center;
line-height: 32px;
background: #ff60a9;
}
.userimage {
float: right;
width: 35px;
height: 35px;
text-align: center;
margin-right: 8px;
padding: 0;
margin-top: 0;
}
.userimage img {
width: 100%;
border-radius: 50%;
}
.userimage img:hover{
transform: scale(1.5);
}
.wc-message-content {
border-radius: 5px 10px 5px;
text-transform: capitalize;
box-shadow: 0px 1px 1px 0px rgba(0, 0, 0, 0.2);
padding: 8px;
word-break: break-word; }
.wc-message-from{
color:#ddd !important; }
.wc-message-from-me {
float: right;
margin-right: 6px; }
.wc-message-from-me.wc-message-from {
text-align: right; }
.wc-message-from-me .wc-message-content {
background-color: #107ad1;background-image: linear-gradient(#8bc4f3, #107ad1);
color: #ffffff; }
.wc-message-from-me svg.wc-message-callout path {
fill: #107ad1; }
.wc-message-from-me svg.wc-message-callout path.point-left {
display: none; }
/* from bot */
.wc-message-from-bot {
float: left;
margin-left: 8px; }
.wc-message-from-bot .wc-message-content {
background-color: #dcdcdc; background-image: linear-gradient(#d0caca, #efefef);
color: #000000; }
.wc-message-from-bot svg.wc-message-callout path {
fill: #dcdcdc; }
.wc-message-from-bot svg.wc-message-callout path.point-right {
display: none; }
.wc-message-from-bot svg.wc-message-callout {
left: -6px; }
</style>
</head>
<body>
<div id="BotChatGoesHere"></div>
<script src="https://cdn.botframework.com/botframework-webchat/latest/botchat.js"></script>
<!-- If you do not want to use Cognitive Services library, comment out the following line -->
<script src="https://cdn.botframework.com/botframework-webchat/latest/CognitiveServices.js"></script>
<script>
const params = BotChat.queryParams(location.search);
const user = {
id: params['userid'] || '5B6RnDTSIA4',
name: params['username'] || 'You',
usernametext:"You"
};
const bot = {
id: params['botid'] || 'mts-bot',
name: params['botname'] || 'ABC'
};
window.botchatDebug = params['debug'] && params['debug'] === 'true';
const styleOptions = {
botAvatarImage: 'https://learn.microsoft.com/en-us/azure/bot-service/v4sdk/media/logo_bot.svg?view=azure-bot-service-4.0',
botAvatarInitials: 'BF',
userAvatarImage: 'https://github.com/compulim.png?size=64',
userAvatarInitials: 'WC'
};
BotChat.App({
bot: bot,
chatTitle:"NIIT Digital Assistant",
locale: params['locale'],
resize: 'detect',
sendTyping: true, // defaults to false. set to true to send 'typing' activities to bot (and other users) when user is typing
speechOptions: speechOptions,
user: user,
styleOptions,
directLine: {
domain: params['webchat.botframework.com'],
secret: params['s'],
token: params['t'],
webSocket: params['webSocket'] && params['webSocket'] === 'true' // defaults to true
}
}, document.getElementById('BotChatGoesHere'));
</script>
</body>
</html>
Unfortunately, there is not a built-in or easy way to do this. You're going to have to cobble together a few additional things to make this work and there isn't really a "standard" answer. However, here's a couple of ways I can think to do this:
Both
Both of my ideas have similar starting components:
Use the employee's code as their user id:
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({
token: 'YOUR_DIRECT_LINE_TOKEN'
}),
userID: <theEmployeeCode>
},
document.getElementById('webchat')
);
Send an Event on Each Page Load
Send an event that fires on each page load
In the bot, by userId, keep track of when each event was received. Something like:
{
<userId>: {
lastJoinEvent: <timeOfLastJoinEvent>
}
}
In the bot, when a join event is received, check if <userId>.lastJoinEvent exists and if it does, you'll want to allow unique sessions after a certain amount of time (say they talked to the bot on a different day), so you'll need some logic that says if <timeOfLastCurrentEvent> - <timeOfLastJoinEvent> > 1 hour (or something), don't send the "session already open" message.
Send Additional Data With Each Message
Generate a constant random id (GUID or random string of some kind) each time the page is loaded, and send that with the activity's ChannelData.
For each message the bot receives from that userId, store an object something like:
{
<userId>: {
lastRandomId: <generatedRandomId>
lastMessageTimestamp: <timeOfLastMessage>
}
}
On each message, update the lastRandomId and the lastMessageTimestamp
In your bot, on each message, check that for the userId, the received randomId matches the lastRandomId. If it does, you can ensure that they're in the same session, so no need to send the "session already open" message.
If they do not match, the sessions are unique. However, you'll want to allow unique sessions after a certain amount of time (say they talked to the bot on a different day), so you'll need some logic that says if <currentMessageTimestamp> - <lastMessageTimestamp> > 1 hour (or something), don't send the "session already open" message.
Now, the problem with this is that you need to make this check on every single message, which is an "expensive" check for something like this. If your bot doesn't have a lot of users and you don't scale it horizontally, you could just store this map in memory--otherwise, you'd need a more permanent storage solution. So, of the two, I'd recommend the first.
All that being said, I recommend against this because:
This can only work in clients that you can either 1) send events on load, or 2) send channelData with every message. So, this would work in Web Chat, but not Teams
This is not easy to implement
If you scale your bot horizontally, you can't store this in memory, which means you're making additional storage API calls fairly frequently. Not too bad for the first options, but rules out the second.
There may be other ways to do this, too, but this is all I can think of.

iText - HTML to PDF - Image is not displayed in PDF

We are using iText.dll of version v1.4.6.2 to generate a horizontal line from an image file.
The below code generates this horizontal line at our local and live system correctly but now its generating line at local system but not on live system.
<div id="'div'_0" type="hrDiv" objtype="10" objtag="" objname="object name" onmouseover="this.className='putpointer'" isitem="" groupid="0" hgroupid="0" associatedlabel="" ishgroupmain="False" canmove="1" lock="false" runat="server" align="left" style="position: absolute; background-color: transparent; display: inline; overflow: hidden; z-index: 10000; left: 41px; top: 122px; width: 720px; height: 25px;" class="putpointer"><img src="http://localhost:1111/images/HorizontalLine.gif" id="'img'_0" type="imgObj" width="720" height="1" style="position: absolute; display: inline; left: 0px; top: 0px; width: 100%;"></div>
Code behind
PdfStamper pdfStamper = null;
pdfStamper = new PdfStamper(pdfReader1, fileStream);
PdfContentByte overContent = pdfStamper.getOverContent(1);
if (true)
{
string str17 = string.Concat(this.strImagepath, "HRline.jpg");
com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(str17);
image.setAbsolutePosition(single, single1 + 20f);
image.scaleAbsolute(single2 - single, 1f);
overContent.addImage(image);
}
Note: Security patches may be installed on server system.

How to select dropdown item with same data-testid

Im trying to get selenium to click an option in a dropdown. There are several options and it looks like the only unique thing about them is the link text. They all have 'data-testid' and they are all the same.
Anyone see a way to click a specific choice within the dropdown?
Here are a few examples of options within the dropdown: (App installs and Lead Generation)
<li class="" data-testid="ads-mini-grouped-objective-selector-option" style=""><div aria-checked="false" aria-disabled="false" class="_2wpb _3v8w" data-testid="SUISelectorOption/container" role="menuitem" style="letter-spacing: normal; color: rgb(75, 79, 86); font-size: 12px; font-weight: normal; font-family: Arial, sans-serif; line-height: 16px; padding: 6px 24px 6px 32px;" tabindex="-1"><span class="_27_z _4s-j" style="margin-left: 0px; margin-right: 8px;"></span><div class="_3leq"><span>App installs</span></div></div></li>
<li class="" data-testid="ads-mini-grouped-objective-selector-option" style="background-color: rgba(29, 33, 41, 0.08);"><div aria-checked="false" aria-disabled="false" class="_2wpb _3v8w" data-testid="SUISelectorOption/container" role="menuitem" style="letter-spacing: normal; color: rgb(75, 79, 86); font-size: 12px; font-weight: normal; font-family: Arial, sans-serif; line-height: 16px; padding: 6px 24px 6px 32px;" tabindex="-1"><span class="_27_z _5da8" style="margin-left: 0px; margin-right: 8px;"></span><div class="_3leq"><span>Lead generation</span></div></div></li>
I have tried to select by link text but that did not work.
To click an option from the Dropdown you can write a function as clickOption() as follows :
public void clickOption(String option)
{
driver.FindElement(By.XPath("//li[#data-testid='ads-mini-grouped-objective-selector-option']//span[.='" + option + "']")).Click();
}
Now, from your main() or #Test annotation Class, call the function clickOption() method with the option which you want to select as follows :
clickOption("App installs");
//or
clickOption("Lead generation");
You can use XPath to select li element by attribute data-testid and inner text :
//li[#data-testid='ads-mini-grouped-objective-selector-option' and .='Lead generation']
driver.findElement(By.xpath("(//li[#data-testid='ads-mini-grouped-objective-selector-option'])[2]")).click();
Try this xpath to click second data with same data-testid:
har07 answer is a good answer,
you can also try this as an option
//*[text()='App installs']/parent::div/parent::div/parent::li
Because not all the html is given, this is the only option i can get

Dynamic text underlined by braces

I want to underline a word with a round brace. This should be part of a C# Text but if it is easier in CSS, no problem. My problem is that the length of the Word can vary, so the bow must by calculated for each word.
My first idea was using CSS box-shadow:
CSS:
#test {
font-size: 50px;
background: transparent;
border-radius: 70px;
height: 65px;
width: 90px;
box-shadow: 0px 6px 0px -2px #00F;
font-family: sans-serif;
}
HTML:
<div id="test">Hey</div>
Unfortunately due to the dynamic Text sizes I can't calculate them.
Is there a smarter approach to this problem?
You don't need to calculate the width if you use span tags instead.
CSS:
.test {
font-size: 50px;
background: transparent;
border-radius: 70px;
height: 65px;
box-shadow: 0px 6px 0px -2px #00F;
font-family: sans-serif;
}
HTML:
<span id="test" class="test">Hey</span><br/>
<span class="test">Hey this is longer</span>
Working Fiddle: http://jsfiddle.net/Ge8Q3/
I found a different approach.
Working fiddle: http://jsfiddle.net/6pEQA/1/
I used javascript and made the width dynamic:
textWidth function taken from here.
$.fn.textWidth = function(){
var self = $(this),
children = self.contents(),
calculator = $('<span style="white-space:nowrap;" />'),
width;
children.wrap(calculator);
width = children.parent().width(); // parent = the calculator wrapper
children.unwrap();
return width;
};
$(document).ready(function(){
$('#test').css('width',$('#test').textWidth());
});
It also works with h1, div or span. You can check my fiddle. Because it is using span elements to calculate width of the element.

Expanding gridview's row

One of gridview's column is a "Content" column that can have few lines of text (it can be literal, textbox or label ).
In "default" mode i want it to show only the first line and a link button: "(more)" or "(read)".
Clicking on this link should expand the column and display full content.
What is the best way to do this?
Selecting first 10 characters of content text and using it as your link's text is better aproach. This will reduce size of data that retrieved from database like that :
SELECT ContentId, SUBSTRING(Content, 0, 10) AS Content
FROM ContentTable;
Then you can use template column for this column that includes a label and a link. Lbel for the description text, link for the details.
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label
Text='<%# Eval("Content") %>'
runat="server"/>
<a href='<%# Eval("ContentId", "contentdetails.aspx?id={0}") %>'>More</a>
</ItemTemplate>
</asp:TemplateColumn>
This will help you.
http://www.asp.net/community/control-gallery/Item.aspx?i=1465
try this. http://mosesofegypt.net/post/BuildingjQueryAndASPNetAJAXEnabledControlsjQueryCollapsiblePanelExtenderPart2.aspx
Use the power of CSS!
Place this inside your gridview row. It will naturally push out the row to the height of your content, or the amount of rows required.
<div class="toggle">
<div class="toggle-header">
Toggle!
</div>
<div class="toggle-height">
<div class="toggle-transform">
<p>2nd line of text</p>
<p>3rd line</p>
<p>4th line</p>
<p>etc</p>
</div>
</div>
</div>
And use this CSS...
body {
font-family: sans-serif;
}
.toggle {
position: relative;
border: 2px solid #333;
border-radius: 3px;
margin: 5px;
width: 200px;
}
.toggle-header {
margin: 0;
padding: 10px;
background-color: #333;
color: white;
text-align: center;
cursor: pointer;
}
.toggle-height {
background-color: tomato;
overflow: hidden;
transition: max-height .6s ease;
max-height: 0;
}
.toggle:hover .toggle-height {
max-height: 1000px;
}
.toggle-transform {
padding: 5px;
color: white;
transition: transform .4s ease;
transform: translateY(-100%);
}
.toggle:hover .toggle-transform {
transform: translateY(0);
}
You may want to disguise the "toggle" with a textbox of your "(more)" line to expand the rest.
Let us know if it worked.

Categories