Skip to content

Commit

Permalink
Merge pull request #15 from pmahend1/dev
Browse files Browse the repository at this point in the history
Migrate cleanup from dev
  • Loading branch information
pmahend1 authored Apr 4, 2021
2 parents 835f3f3 + e2c6c86 commit 4743da2
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 245 deletions.
4 changes: 4 additions & 0 deletions .Net Core/MSRewards/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public static class Constants

public const string ID_P = "id_p";

public const string ID_L = "id_l";

public const string ID_A = "id_a";

public const string B_Results = "b_results";
Expand All @@ -42,6 +44,8 @@ public static class Constants

public const string BingSearchURL = "http://www.bing.com/search?q=";

public const string BingHome = "http://www.bing.com/";

public const string GeckoPathKey = "webdriver.gecko.driver";

public const string UserAgentKey = "general.useragent.override";
Expand Down
56 changes: 56 additions & 0 deletions .Net Core/MSRewards/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using System;

namespace MSRewards
{
public static class Extensions
{
public static bool IsClickable(this IWebElement webElement)
{
if (webElement != null)
return webElement.Displayed && webElement.Enabled;
else
return false;
}

public static IWebElement FindClickableElement(this IWebDriver driver, By condition, int fromSeconds = 10)
{
bool isElementPresent = false;
IWebElement singleElement = null;

var driverWait = new WebDriverWait(driver, TimeSpan.FromSeconds(fromSeconds));
driverWait.IgnoreExceptionTypes(typeof(NoSuchElementException));

try
{
isElementPresent = driverWait.Until(d => d.FindElement(condition).IsClickable());

if (isElementPresent)
{
singleElement = driver.FindElement(condition);
}
}
catch
{
// log any errors
}

return singleElement;
}

public static bool WaitUntilClickable(this IWebDriver driver, By condition, int fromSeconds = 10)
{
var element = driver.FindClickableElement(condition, fromSeconds);
return (element != null);
}


public static void WaitUntilElementFound(this IWebDriver driver, By condition, int fromSeconds = 10)
{
WebDriverWait waiter = new WebDriverWait(driver, TimeSpan.FromSeconds(fromSeconds));
waiter.IgnoreExceptionTypes(typeof(NoSuchElementException));
waiter.Until(d => d.FindElement(condition) != null);
}
}
}
3 changes: 2 additions & 1 deletion .Net Core/MSRewards/MSRewards.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="dein.Colorify" Version="2.6.0" />
<PackageReference Include="Selenium.Firefox.WebDriver" Version="0.27.0" />
<PackageReference Include="Selenium.Support" Version="4.0.0-beta1" />
<PackageReference Include="Selenium.WebDriver" Version="4.0.0-beta1" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="88.0.705.56" />
<PackageReference Include="Selenium.WebDriver.MSEdgeDriver" Version="89.0.774.54" />
</ItemGroup>
</Project>
Loading

0 comments on commit 4743da2

Please sign in to comment.