How to FindElement By Xpath in Selenium PhantomJS C# - c#

This is the structure:
<div id="footer">
<div id="debugTxt" style="color:blue;">Wed Jul 27 2016 10:06:12 GMT+0800 (Sample)Sample<br>
Sample<br>
Wed Jul 27 2016 10:06:12 GMT+0800 (Sample) Sample<br>
Wed Jul 27 2016 10:06:12 GMT+0800 (Sample) Sample!<br>
Wed Jul 27 2016 10:06:12 GMT+0800 (Sample) <br>
DataTOGET:http://Please.Get.Me<br>
</div>
</div>
This is what I'm trying to do:
driver1.FindElement(By.XPath(".//*[#id='debugTxt']")).GetAttribute("value");
Is it possible to get the value of http://Please.Get.Me ?

You should just tweak your expression to match the a element inside the div:
driver1.FindElement(By.XPath(".//*[#id='debugTxt']/a")).GetAttribute("href");

With a little tweak and help from alecxe
driver1.FindElement(By.XPath("//*[#id='debugTxt']//a")).GetAttribute("href");

I think you want visible text of the link, you should try using .Text as below :-
driver1.FindElement(By.XPath(".//*[#id='debugTxt']/a")).Text;

Related

Missing "Microsoft.CodeAnalysis" in .net 3.1 install on Ubuntu

I have a .net project that runs in windows with VS code with no issues.
I am trying to run the same project in Ubuntu 20.04.2 with VS code. Run trying to run it with F5, I get the errors:
CSC : error CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from /home/one/.nuget/packages/system.text.json/6.0.6/analyzers/dotnet/roslyn3.11/cs/System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=****'. The system cannot find the file specified.. [/home/one/github/fhir/Foo.Service/Foo.Service/Foo.Service.csproj]
CSC : error CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from /home/one/.nuget/packages/system.text.json/6.0.6/analyzers/dotnet/roslyn4.0/cs/System.Text.Json.SourceGeneration.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=******'. The system cannot find the file specified.. [/home/one/github/fhir/Foo.Service/Foo.Service/Foo.Service.csproj]
I verified the files are on my system:
roslyn3.11
% lr /home/one/.nuget/packages/system.text.json/6.0.6/analyzers/dotnet/roslyn3.11/cs/System.Text.Json.SourceGeneration.dll
-rwxrw-r-- 1 one one 148K Aug 19 19:48 /home/one/.nuget/packages/system.text.json/6.0.6/analyzers/dotnet/roslyn3.11/cs/System.Text.Json.SourceGeneration.dll
roslyn4.0
one#work ~
% lr /home/one/.nuget/packages/system.text.json/6.0.6/analyzers/dotnet/roslyn4.0/cs/System.Text.Json.SourceGeneration.dll
-rwxrw-r-- 1 one one 164K Aug 19 19:48 /home/one/.nuget/packages/system.text.json/6.0.6/analyzers/dotnet/roslyn4.0/cs/System.Text.Json.SourceGeneration.dll
csproj
one#work ~
% lr /home/one/github/fhir/Foo.Service/Foo.Service/Foo.Service.csproj
-rw-rw-r-- 1 one one 1.8K Nov 10 16:59 /home/one/github/fhir/Foo.Service/Foo.Service/Foo.Service.csproj
It looks like "Microsoft.CodeAnalysis" was missing. So, I installed it with nuget in VS code. I added 'nuget: add package' in VS code to install 'Microsoft.CodeAnalaysis' version 3.11.0.
I have verified it successfully lives on my system:
one#work ...packages/microsoft.codeanalysis/3.11.0
% pwd
/home/one/.nuget/packages/microsoft.codeanalysis/3.11.0
one#work ...packages/microsoft.codeanalysis/3.11.0
% lr
total 80K
drwxrwxr-x 2 one one 4.0K Nov 14 10:08 .
drwxrwxr-x 4 one one 4.0K Nov 14 10:08 ..
-rw-rw-r-- 1 one one 178 Nov 14 10:08 .nupkg.metadata
-rwxrw-r-- 1 one one 19K Aug 10 2021 .signature.p7s
-rwxrw-r-- 1 one one 6.9K Apr 30 2021 Icon.png
-rwxrw-r-- 1 one one 2.2K Aug 3 2021 ThirdPartyNotices.rtf
-rw-rw-r-- 1 one one 28K Nov 14 10:08 microsoft.codeanalysis.3.11.0.nupkg
-rw-rw-r-- 1 one one 88 Nov 14 10:08 microsoft.codeanalysis.3.11.0.nupkg.sha512
-rwxrw-r-- 1 one one 2.4K Aug 3 2021 microsoft.codeanalysis.nuspec
I still get the errors mentioned above.

DST Entry time for few Timezone (Europe/Nicosia) are reporting wrong date using System.Globalization C#

I'm trying to get the DST entry time for the timezone "Antarctica/McMurdo" for the current year 2020 using System.Globalization class in C#. i'm receiving them as
DST Entry Time: 9/29/2020 2:00:00 AM
DST Exit Time: 4/5/2020 2:59:59 AM
But the actual DST entry time supposed to be on 9/27/2020 2:00:00 AM according to https://www.timeanddate.com/time/change/antarctica/mcmurdo
The received entry time is already in DST because of which my test program is failing as the time shift is not happening.
Below is the code snippet used
var currTimeZone = TimeZone.CurrentTimeZone;
var dstInfo = currTimeZone.GetDaylightChanges(now.Year);
DSTEntry = dstInfo.Start.ToString();
Below are the versions of Mono and Ubuntu i'm running on
Ubuntu 16.04.3 LTS
Mono JIT compiler version 5.4.0.201
Here is the output of zdump
$ zdump Antarctica/McMurdo -v 2019,2022
Antarctica/McMurdo Sat Apr 6 13:59:59 2019 UT = Sun Apr 7 02:59:59 2019 NZDT isdst=1 gmtoff=46800
Antarctica/McMurdo Sat Apr 6 14:00:00 2019 UT = Sun Apr 7 02:00:00 2019 NZST isdst=0 gmtoff=43200
Antarctica/McMurdo Sat Sep 28 13:59:59 2019 UT = Sun Sep 29 01:59:59 2019 NZST isdst=0 gmtoff=43200
Antarctica/McMurdo Sat Sep 28 14:00:00 2019 UT = Sun Sep 29 03:00:00 2019 NZDT isdst=1 gmtoff=46800
Antarctica/McMurdo Sat Apr 4 13:59:59 2020 UT = Sun Apr 5 02:59:59 2020 NZDT isdst=1 gmtoff=46800
Antarctica/McMurdo Sat Apr 4 14:00:00 2020 UT = Sun Apr 5 02:00:00 2020 NZST isdst=0 gmtoff=43200
Antarctica/McMurdo Sat Sep 26 13:59:59 2020 UT = Sun Sep 27 01:59:59 2020 NZST isdst=0 gmtoff=43200
Antarctica/McMurdo Sat Sep 26 14:00:00 2020 UT = Sun Sep 27 03:00:00 2020 NZDT isdst=1 gmtoff=46800
Antarctica/McMurdo Sat Apr 3 13:59:59 2021 UT = Sun Apr 4 02:59:59 2021 NZDT isdst=1 gmtoff=46800
Antarctica/McMurdo Sat Apr 3 14:00:00 2021 UT = Sun Apr 4 02:00:00 2021 NZST isdst=0 gmtoff=43200
Antarctica/McMurdo Sat Sep 25 13:59:59 2021 UT = Sun Sep 26 01:59:59 2021 NZST isdst=0 gmtoff=43200
Antarctica/McMurdo Sat Sep 25 14:00:00 2021 UT = Sun Sep 26 03:00:00 2021 NZDT isdst=1 gmtoff=46800
Can someone help me how to resolve this timing issue? or is this a bug from DLL/timezone_database which C# is reading from?
Thanks
From the documentation on the TimeZone class:
Warning
This API is now obsolete
...
ⓘ Important
Whenever possible, use the TimeZoneInfo class instead of the TimeZone
class.
...
The TimeZone class supports only a single daylight saving time
adjustment rule for the local time zone. As a result, the TimeZone
class can accurately report daylight saving time information or
convert between UTC and local time only for the period in which the
latest adjustment rule is in effect. In contrast, the TimeZoneInfo
class supports multiple adjustment rules, which makes it possible to
work with historic time zone data.
In short, don't use the TimeZone class.

Unclear Sqlite exception after updating my UWP app

After updating the UWP app, I get many crash from the different sections of the app
STOWED_EXCEPTION_Microsoft.Data.Sqlite.SqliteException_80131500***APP-NAME***.dll!Microsoft::Data::Sqlite::SqliteCommand.ExecuteReader
Which did not happend in previous version, I also did not change the database access code section nor updated/reinstalled the EF Sqlite nugget package.
Here are Stacktrace i have received from users:
Thanks
Frame Image Function Offset
0 Microsoft.Data.Sqlite.dll Microsoft::Data::Sqlite::Interop::MarshalEx.ThrowExceptionForRC 0x0000000000000067
1 Microsoft.Data.Sqlite.dll Microsoft::Data::Sqlite::SqliteCommand.ExecuteReader 0x000000000000012F
2 Microsoft.Data.Sqlite.dll Microsoft::Data::Sqlite::SqliteCommand.ExecuteDbDataReader 0x000000000000000B
3 EntityFramework.Relational.dll Microsoft::Data::Entity::Storage::Internal::RelationalCommand::__c__DisplayClass17_0._ExecuteReader_b__0$catch$0 0x0000000000000013
4 SharedLibrary.dll System::Func$1_System::__Canon_.Invoke 0x0000000000000013
5 EntityFramework.Relational.dll Microsoft::Data::Entity::Storage::Internal::RelationalCommand.Execute_System.__Canon_$catch$0 0x00000000000000C1
6 EntityFramework.Relational.dll Microsoft::Data::Entity::Storage::Internal::RelationalCommand.ExecuteReader 0x0000000000000057
7 EntityFramework.Relational.dll Microsoft::Data::Entity::Query::Internal::QueryingEnumerable::Enumerator.MoveNext 0x000000000000008B
8 EntityFramework.Relational.dll Microsoft::Data::Entity::Query::QueryMethodProvider.GetResult_System.Int32_ 0x000000000000003D
9 APPNAME.McgInterop.dll _$ILCT$::$ILT$ReflectionDynamicInvoke$.InvokeRetOI_System.__Canon,System.Int32 0x0000000000000061
10 SharedLibrary.dll System::InvokeUtils.CallIHelperStaticCallWithInstantiation 0x0000000000000023
11 SharedLibrary.dll System::InvokeUtils.CallDynamicInvokeMethod 0x0000000000000119
12 System.Linq.Expressions System::Linq::Expressions::Interpreter::MethodInfoCallInstruction.InvokeWorker$catch$0 0x0000000000000017
13 System.Linq.Expressions System::Linq::Expressions::Interpreter::MethodInfoCallInstruction.Invoke 0x0000000000000009
14 System.Linq.Expressions System::Linq::Expressions::Interpreter::MethodInfoCallInstruction.Run 0x0000000000000065
15 System.Linq.Expressions System::Linq::Expressions::Interpreter::Interpreter.Run 0x0000000000000027
16 System.Linq.Expressions System::Linq::Expressions::Interpreter::LightLambda.Run 0x000000000000009B
17 SharedLibrary.dll System::Runtime::CompilerServices::ConditionalWeakTable$2_System::__Canon,System::__Canon_::CreateValueCallback.InvokeObjectArrayThunk 0x0000000000000037
18 EntityFramework.Core.dll Microsoft::Data::Entity::Query::Internal::QueryCompiler::__c__DisplayClass18_1$1_System::Int32_._CompileQuery_b__1$catch$0 0x0000000000000059
19 SharedLibrary.dll System::Comparison$1_System::__Canon_.Invoke 0x0000000000000013
20 EntityFramework.Core.dll Microsoft::Data::Entity::Query::Internal::QueryCompiler.Execute_System.Int32_ 0x000000000000003D
21 EntityFramework.Core.dll Microsoft::Data::Entity::Query::Internal::EntityQueryProvider.Execute_System.Int32_ 0x0000000000000033
22 System.Linq.Queryable.dll System::Linq::Queryable.Count_System.Int32_ 0x0000000000000121
23 APPNAME*.exe InstagramDownloader::pgHome._imgDownloader_b__15_4 0x0000000000000167
24 APPNAME*.McgInterop.dll Windows::System::Threading::TimerElapsedHandler.Invoke 0x000000000000000F
25 APPNAME*.McgInterop.dll McgInterop::ReverseComSharedStubs.Proc_ 0x0000000000000015
26 SharedLibrary.dll System::Runtime::ExceptionServices::ExceptionDispatchInfo.Throw 0x0000000000000019
27 System.Private.Threading System::Runtime::CompilerServices::TaskAwaiter.ThrowForNonSuccess 0x0000000000000053
28 System.Private.Threading System::Runtime::CompilerServices::TaskAwaiter.HandleNonSuccessAndDebuggerNotification 0x000000000000002D
29 System.Private.Threading System::Runtime::CompilerServices::TaskAwaiter.ValidateEnd 0x000000000000001D
30 System.Private.Threading System::Runtime::CompilerServices::TaskAwaiter.GetResult 0x000000000000000B
31 APPNAME*.exe InstagramDownloader::pgHome::_imgDownloader_d__15.MoveNext 0x00000000000015AF
32 SharedLibrary.dll System::Runtime::ExceptionServices::ExceptionDispatchInfo.Throw 0x0000000000000019
33 System.Private.Threading System::Runtime::CompilerServices::TaskAwaiter.ThrowForNonSuccess 0x0000000000000053
34 System.Private.Threading System::Runtime::CompilerServices::TaskAwaiter.HandleNonSuccessAndDebuggerNotification 0x000000000000002D
35 System.Private.Threading System::Runtime::CompilerServices::TaskAwaiter.ValidateEnd 0x000000000000001D
36 System.Private.Threading System::Runtime::CompilerServices::TaskAwaiter.GetResult 0x000000000000000B
37 APPNAME*.exe InstagramDownloader::pgHome::_btnDownload_Click_d__17.MoveNext 0x000000000000025D
38 APPNAME*.McgInterop.dll McgInterop::McgHelpers.ThrowFailed 0x0000000000000033
39 APPNAME*.McgInterop.dll McgInterop::ComCallHelpers.ComCall__HRESULT 0x00000000000000A9
40 APPNAME*.McgInterop.dll McgInterop::ForwardComSharedStubs.Func_TResult___System.__Canon,_System.__Canon_ 0x000000000000002B
41 APPNAME*.McgInterop.dll Windows::UI::Popups::MessageDialog.ShowAsync 0x0000000000000011
42 APPNAME*.exe InstagramDownloader::pgHome::_btnDownload_Click_d__17.MoveNext$catch$0 0x000000000000002F
43 SharedLibrary.dll System::Runtime::ExceptionServices::ExceptionDispatchInfo.Throw 0x0000000000000019
44 System.Private.Threading System::Runtime::CompilerServices::AsyncMethodBuilderCore::__c._ThrowAsync_b__9_0 0x0000000000000013
45 System.Private.Threading System::Threading::WinRTSynchronizationContext::Invoker.InvokeCore 0x0000000000000033
I suggest updating all SQLite-related packages on NuGet as well as the SQLite extension for Visual Studio (via Tools -> Extensions and Updates...)
Update
As I have learned, you use EntityFrameworkCore, which works only with Windows 10 Fall Creators Update and newer and will not work on older versions of UWP. To get rid of the issues, you will have to set your app to have minimum SDK version 16299 (FCU). If you need to support older versions, you will have to work without Entity Framework for now...

OpenVpn from C# - Weird Timeout

i am trying to start OpenVpn from my C# Windows Service. Basically like this:
VpnProcess = new Process();
VpnProcess.StartInfo.FileName = "<Path to openvpn.exe in Program dir>";
VpnProcess.StartInfo.Arguments = "--config " + "<vpnConfigName>" + " --log vpn.log";
VpnProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
VpnProcess.StartInfo.UseShellExecute = false;
VpnProcess.StartInfo.CreateNoWindow = true;
VpnProcess.StartInfo.WorkingDirectory = <Program dir>;
VpnProcess.Start();
so far so good, here is the resulting log:
Tue Sep 01 11:01:15 2015 OpenVPN 2.3.8 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [PKCS11] [IPv6] built on Aug 4 2015
Tue Sep 01 11:01:15 2015 library versions: OpenSSL 1.0.1p 9 Jul 2015, LZO 2.08
Tue Sep 01 11:01:16 2015 Socket Buffers: R=[8192->8192] S=[8192->8192]
Tue Sep 01 11:01:16 2015 UDPv4 link local: [undef]
Tue Sep 01 11:01:16 2015 UDPv4 link remote: [AF_INET]217.79.181.93:1194
Tue Sep 01 11:01:16 2015 TLS: Initial packet from [AF_INET]217.79.181.93:1194, sid=a7a52cba 93615557
Tue Sep 01 11:01:16 2015 VERIFY OK: depth=1, CN=<censored>
Tue Sep 01 11:01:16 2015 VERIFY OK: nsCertType=SERVER
Tue Sep 01 11:01:16 2015 VERIFY OK: depth=0, C=<censored>, ST=<censored>, L=<censored>, O=<censored>, OU=<censored>, CN=<censored>, name=<censored>, emailAddress=<censored>
Tue Sep 01 11:02:16 2015 [<censored>] Inactivity timeout (--ping-restart), restarting
Tue Sep 01 11:02:16 2015 SIGUSR1[soft,ping-restart] received, process restarting
Tue Sep 01 11:02:16 2015 Restart pause, 2 second(s)
Tue Sep 01 11:02:18 2015 Socket Buffers: R=[8192->8192] S=[8192->8192]
Tue Sep 01 11:02:19 2015 UDPv4 link local: [undef]
Tue Sep 01 11:02:19 2015 UDPv4 link remote: [AF_INET]217.79.181.93:1194
Tue Sep 01 11:02:19 2015 TLS: Initial packet from [AF_INET]217.79.181.93:1194, sid=4963868b 6f0eecb7
Tue Sep 01 11:02:20 2015 VERIFY OK: depth=1, CN=<censored>
Tue Sep 01 11:02:20 2015 VERIFY OK: nsCertType=SERVER
Tue Sep 01 11:02:20 2015 VERIFY OK: depth=0, C=<censored>, ST=<censored>, L=<censored>, O=<censored>, OU=<censored>, CN=<censored>, name=<censored>, emailAddress=<censored>
Tue Sep 01 11:02:21 2015 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
[...]
Tue Sep 01 11:02:28 2015 Initialization Sequence Completed
So, vpn hangs after VERIFY, then restarts itself, then its working fine. If i start openvn via cmd or Powershell with the exact same conditions and params, it connects successfully in the first try.
I spent several days trying to find out why this happens, no success. I tried all sensible combinations of StartInfo-Properties and checked whether the executing user changes after the soft restart. Nope, both times it's LocalSystem.
Cause: server time was 1 minute ahead of time. So the freshly downloaded certificate on client was 'from the future', leading to rejection by the server. Server log showed this, but never client log
Check your OpenVPN config file do you have option 'auth-nocache'.
I got a similar effect when I've added this option to client configuration. I use username / password to authenticate.

Test Webservice Method in Visual Studio: why does it say runs successfully without running the test and test fails?

I have created the default webservice asmx hello world :
namespace WebServiceHello
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
I then generate a MS Test with Visual Studio and set expected value:
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("C:\\temp\\WebServiceHello\\WebServiceHello", "/")]
[UrlToTest("http://localhost:7352/")]
public void HelloWorldTest()
{
Service1 target = new Service1(); // TODO: Initialize to an appropriate value
string expected = "Hello World"; // TODO: Initialize to an appropriate value
string actual;
actual = target.HelloWorld();
Assert.AreEqual(expected, actual);
// Assert.Inconclusive("Verify the correctness of this test method.");
}
but I got this error message:
The Web request
'http://localhost:7352/' completed
successfully without running the test.
This can occur when configuring the
Web application for testing fails (an
ASP.NET server error occurs when
processing the request), or when no
ASP.NET page is executed (the URL may
point to an HTML page, a Web service,
or a directory listing). Running tests
in ASP.NET requires the URL to resolve
to an ASP.NET page and for the page to
execute properly up to the Load event.
The response from the request is
stored in the file
'WebRequestResponse_HelloWorldTest.html'
with the test results; typically this
file can be opened with a Web browser
to view its contents.
and as Test Files :
WebRequestResponse_HelloWorldTest.html
which contains
<html>
<head>
<title>Directory Listing -- /</title>
<style>
body {font-family:"Verdana";font-weight:normal;font-size: 8pt;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: 8pt}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<h2> <i>Directory Listing -- /</i> </h2></span>
<hr width=100% size=1 color=silver>
<PRE>
Saturday, September 25, 2010 06:39 PM <dir> App_Data
Saturday, September 25, 2010 06:40 PM <dir> bin
Saturday, September 25, 2010 06:39 PM <dir> obj
Saturday, September 25, 2010 06:39 PM <dir> Properties
Saturday, September 25, 2010 06:39 PM 97 Service1.asmx
Saturday, September 25, 2010 06:39 PM 572 Service1.asmx.cs
Saturday, September 25, 2010 06:44 PM 3,551 Web.config
Saturday, September 25, 2010 06:39 PM 968 web.config.backup
Saturday, September 25, 2010 06:39 PM 1,285 Web.Debug.config
Saturday, September 25, 2010 06:39 PM 1,346 Web.Release.config
Saturday, September 25, 2010 06:40 PM 3,805 WebServiceHello.csproj
Saturday, September 25, 2010 06:40 PM 1,086 WebServiceHello.csproj.user
</PRE>
<hr width=100% size=1 color=silver>
<b>Version Information:</b> ASP.NET Development Server 10.0.0.0
</font>
</body>
</html>
The test shouldn't fail since actual is expected so what I did setup wrongly ?
Create Default.aspx page in project with service
Answer valid for: Vista, VS2008 (may work for VS2010)
Run VS as admin (it's enough to be part of Administrators group)
Create Default.aspx page in the project
http://msdn.microsoft.com/en-us/library/ms243399(v=vs.90).aspx

Categories