Extract string value from md-card - c#

I want to extract the string value (Email is verified successfully!) from the md-card using Selenium.
<md-card ng-if="$ctrl.isMyCompany && $ctrl.showVerified" class="ng-scope _md">
<md-card-content class="tradingPartnerVerification-warn ng-binding layout-align-start-center" layout-align="start center">
<md-icon class="myCompany-verifiedEmailIcon" md-svg-icon="check-circle" role="img" aria-label="check-circle">
<svg xmlns="http://www.w3.org/2000/svg" fit="" height="100%" width="100%" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24" focusable="false">
<g id="check-circle">
<path d="M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22A10,10 0 0,1 2,12A10,10 0 0,1 12,2M11,16.5L18,9.5L16.59,8.09L11,13.67L7.91,10.59L6.5,12L11,16.5Z"></path>
</g>
</svg>
</md-icon>
Email is verified successfully!
</md-card-content>
</md-card>
I'm using .Net with NUnit framework. My code is below.
string ActualEmailVerifiedText = diver.FindElement(By.XPath("//md-card-content[#class='tradingPartnerVerification-warn ng-binding layout-align-start-center']")).Text;

I think it is possible that some class is being added in md-card-content in runtime (assuming you are misspeling driver only here)
Try this:
string ActualEmailVerifiedText = driver.FindElement(
By.XPath("//md-card-content[contains(#class,'tradingPartnerVerification-warn')]")
).getAttribute('textContent');

To extract the string Email is verified successfully! you need to induce WebDriverWait for the text to render within the HTML as follows :
wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
string myElement = wait.Until(ExpectedConditions.TextToBePresentInElementLocated(By.XPath("//md-card[#class='ng-scope _md']/md-card-content[#class='tradingPartnerVerification-warn ng-binding layout-align-start-center']"),"Email is verified successfully!"));
Console.WriteLine(myElement.Text);

Related

Inserting a new element after an existing element in an SVG (XML)

I want to insert an element after an existing element. For example, in this simple XML file, I want to insert an element after the "defs" element.
<?xml version="1.0" standalone="no"?>
<svg viewBox="0 0 790 790" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" stroke-linecap="round" stroke-linejoin="round" fill-rule="evenodd" xml:space="preserve" >
<defs >
<clipPath id="clipId0" >
<path d="M0,790 790,790 790,0 0,0 z" />
</clipPath>
</defs>
****I WANT TO INSERT MY NEW ELEMENT HERE
<g clip-path="url(#clipId0)" fill="none" stroke="rgb(0,0,0)" stroke-width="0.5" />
<g clip-path="url(#clipId0)" fill="rgb(0,255,0)" stroke="rgb(0,255,0)" stroke-width="0" >
<text transform="matrix(12.0023 0 -0 12.0023 130.206 546.583)" font-family="Arial,'sans-serif'" font-size="1.39636" >WORK REGION</text>
</g>
</svg>
Here is my attempted c# code:
public void AddBlackBackground(string xOrig, string yOrig, string xExt, string yExt )
{
XElement xE = new XElement("rect");
xE.Add(new XAttribute("x", xOrig));
xE.Add(new XAttribute("y", xOrig));
xE.Add(new XAttribute("width", xOrig));
xE.Add(new XAttribute("height", xOrig));
xE.Add(new XAttribute("style", "fill:black"));
XElement root = _XML_Doc.Root.Element("svg");
XElement defs = root.Element("defs");
defs.AddAfterSelf(xE);
}
The XElements root and defs are null when I run the code, so naturally the line defs.AddAfterSelf(xE); throws an Object reference not set error.
Any guidance is appreciated.
Try this with namespace
var ns = _XML_Doc.Root.Name.Namespace;
XElement root = _XML_Doc.Element(ns +"svg");
XElement defs = root.Element(ns + "defs");
defs.AddAfterSelf(xE);
Or to ignore namespace
_XML_Doc.Root
.DescendantsAndSelf()
.Elements()
.Single(d => d.Name.LocalName == "defs")
.AddAfterSelf(xE);

Getting the placeholder values with Open XML SDK 2.0

I'm trying to drill down through a shapetree in a PowerPoint slide to get a shape's placeholder values. The shape on the shapetree looks like this:
<p:sp>
<p:nvSpPr>
<p:cNvPr id="10" name="Text Placeholder 2"/>
<p:cNvSpPr>
<a:spLocks noGrp="1"/>
</p:cNvSpPr>
<p:nvPr>
<p:ph type="body" sz="quarter" idx="13" hasCustomPrompt="1"/>
</p:nvPr>
</p:nvSpPr>
<p:spPr>
<a:xfrm>
<a:off x="457200" y="3276601"/>
<a:ext cx="8229600" cy="838199"/>
</a:xfrm>
<a:prstGeom prst="rect">
<a:avLst/>
</a:prstGeom>
</p:spPr>
<p:txBody>
<a:bodyPr lIns="91421" tIns="45710" rIns="91421" bIns="45710"/>
<a:lstStyle>
<a:lvl1pPr marL="0" indent="0" algn="ctr">
<a:buFontTx/>
<a:buNone/>
<a:defRPr sz="2400" b="1" baseline="0">
<a:solidFill>
<a:schemeClr val="tx1"/>
</a:solidFill>
<a:latin typeface="+mj-lt"/>
<a:cs typeface="Arial" pitchFamily="34" charset="0"/>
</a:defRPr>
</a:lvl1pPr>
</a:lstStyle>
<a:p>
<a:pPr lvl="0"/>
<a:r>
<a:rPr lang="en-US" dirty="0" smtClean="0"/>
<a:t>Click to enter course title</a:t>
</a:r>
</a:p>
</p:txBody>
</p:sp>
The part I'm interested in getting looks like this:
<p:nvPr>
<p:ph type="body" sz="quarter" idx="13" hasCustomPrompt="1"/>
</p:nvPr>
I'm trying to get the idx value (13, in this case).
The statement I'm using looks like this, so far (I'm saying "so far" because I don't know how to finish the statement):
var index = shape.NonVisualShapeProperties.NonVisualShapeDrawingProperties. <-???
At this point in the code, I have the shape I want, I just can't figure out how to get the placeholder values using Open Office SDK. I guess I could just treat it as plain old XML and get it by element name, but I figured the OOXML SDK would have some method built-in for this.
Finally figured out how to do this:
index = int.Parse(shape.NonVisualShapeProperties.ApplicationNonVisualDrawingProperties.PlaceholderShape.Index);
I was using NonVisualShapeDrawingProperties when I should have been using ApplicationNonVisualDrawingProperties.

How to unwrap an element if it exists with CsQuery?

I'm using CsQuery to read values of HTML elements.
In advance, I don't know if the <a> element contains a <font> element or not.
Is there a way to read the InnerText of an anchor regardless if it contains a fontelement or not?
Scenario 1: Text inside font element
<div class="link">
<a href="http://www.example.com/1">
<font>Foo</font>
</a>
</div>
Scenario 2: Text without font element
<div class="link">
<a href="http://www.example.com/2">
Foo
</a>
</div>
I've got the following working solution:
var dom = CQ.CreateFromUrl("http://www.myurl.com");
var a = new CQ(dom.Select("div.link a").InnerHTML);
var font = a.Select("font");
var myValue = a.Count() > 0 ? font[0].InnerText : a[0].InnerText;
But it's a bit messy and I'd rather just always remove the font element - if present - so I could go for the anchor value right away. Something like Contents() in combination with UnWrap(), but I haven't succeeded to make it work. Ideas anyone?
var dom = CQ.CreateFromUrl("http://www.myurl.com");
string result = dom[".link a"].Text();

How to find specific value of the node in xml file

I am making windows phone 8 app based the webservices. This is my xml code:
- <response>
<timestamp>2013-10-31T08:30:56Z</timestamp>
<resultsOffset>0</resultsOffset>
<status>success</status>
<resultsLimit>8</resultsLimit>
<resultsCount>38</resultsCount>
- <headlines>
- <headlinesItem>
<headline>City edge past Toon</headline>
<keywords />
<lastModified>2013-10-30T23:45:22Z</lastModified>
<audio />
<premium>false</premium>
+ <links>
- <api>
- <news>
<href>http://api.espn.com/v1/sports/news/1600444?region=GB</href>
</news>
</api>
- <web>
<href>http://espnfc.com/uk/en/report/381799/city-edge-toon?ex_cid=espnapi_public</href>
</web>
- <mobile>
<href>http://m.espn.go.com/soccer/gamecast?gameId=381799&lang=EN&ex_cid=espnapi_public</href>
</mobile>
</links>
<type>snReport</type>
<related />
<id>1600444</id>
<story>Alvardo Negredo and Edin Dzeko struck in extra-time to book Manchester City's place in the last eight of the Capital One Cup, while Costel Pantilimon kept a clean sheet in the 2-0 win to keep the pressure on Joe Hart. </story>
<linkText>Newcastle 0-2 Man City</linkText>
- <images>
- <imagesItem>
<height>360</height>
<alt>Man City celebrate after Edin Dzeko scored their second extra-time goal at Newcastle.</alt>
<width>640</width>
<name>Man City celeb Edin Dzeko goal v nufc 20131030 [640x360]</name>
<caption>Man City celebrate after Edin Dzeko scored their second extra-time goal at Newcastle.</caption>
<type>inline</type>
<url>http://espnfc.com/design05/images/2013/1030/mancitycelebedindzekogoalvnufc20131030_640x360.jpg</url>
</imagesItem>
</images>
Code behind:
myData = XDocument.Parse(e.Result, LoadOptions.None);
var data = myData.Descendants("headlines").FirstOrDefault();
var data1 = from query in myData.Descendants("headlinesItem")
select new UpdataNews
{
News = (string)query.Element("headline").Value,
Desc = (string)query.Element("description"),
Newsurl = (string)query.Element("links").Element("mobile").Element("href"),
Imageurl = (string)query.Element("images").Element("imagesItem").Element("url").Value,
};
lstShow.ItemsSource = data1;
I am trying to get value from xml tags and assign them to News,Desc, etc. Everything works fine except Imageurl, it shows NullException. I tried same method for Imageurl, I don't know what's going wrong.
You arelooking for:
Imageurl=(string)query.Element("images").Element("imagesItem").Element("url").Value
but "imagesItem" is not a child element to "images", it's a sibling.
Edited
Ok, it is probably because the <"url"> element is missing from one of the paths. So, take that into account.
Imageurl=query.Element("images").Element("imagesItem").Element("url") != null ? Imageurl=(string)query.Element("images").Element("imagesItem").Element("url").Value : "no image",

XML parsing : Reading CDATA

<item><title>this is title</title><guid isPermaLink="true">http://www.i.com/video/nokia-lumia-920-deki-pureview_2879.html</guid><link>http://www.i.com/video/nokia-lumia-920-deki-pureview_2879.html</link>
<description><![CDATA[this is the info.]]></description>
<pubDate>Wed, 5 Sep 2012 22:10:00 UT</pubDate>
<media:content type="image/jpg" expression="sample" fileSize="2956" medium="image" url="http://media.chip.com.tr/images/content/video/88/201209060102428081-0.jpg"/>
<enclosure type="image/jpg" url="http://media.chip.com.tr/images/content/video/88/201209060102428081-0.jpg" length="2956"/></item>
I want read the CDATA in <"description">
I wrote this
var x = e.Result;// e is downlaoded xml file
var videos = XElement.Parse(e.Result);
var fList = (from haber in videos.Descendants("channel").Elements("item")
select new Video
{
title = haber.Element("title").Value,
link = haber.Element("link").Value,
//description = ???????
}).ToList();
what should i write to description ? //EDIT Answer: The same way
but if the description like this?
<![CDATA[<p>Zombiler adına ne umduk ne bulduk!</p> <p> </p><p><img style="margin: 5px 0px 5px 5px; border: 1px solid #333333; float: right;" alt="Black_ops" src="http://or.com/images/stories/haber/haberler6/20120918_Castlevania/Black_ops.jpg" height="0" width="0" /><strong>Black Ops 2</strong>'de Zombi modu olabilir haberi çıktığından beri bir ses, bir görüntü beklerken <strong>Call of Duty</strong>'nin resmi <strong>Youtube</strong> sayfasında aşağıdaki video yayınlandı. Açıkçası ne demek istiyorlar anlamak güç. <p>Devamını oku...</p>]]>
You should be able to use exactly the same code:
description = haber.Element("description").Value
Or
description = (string) haber.Element("description")
LINQ to XML will take care of reading the text for you.
To read the CDATA block you just use the same methods; you what you want is to clean the HTML from it, then check this answer.

Categories

Resources