26 Eylül 2014 Cuma

Selenium click işleri 2

IWebElement element = driver.FindElement(By.XPath("//img[@name='jack']"));
new Actions(driver).MoveToElement(element).Perform(); //Here i am moving driver to that element.
ILocatable loc = (ILocatable)element;       // Here i am getting co-ordinates of that element.
 IMouse mouse = ((IHasInputDevices)driver).Mouse; // Here i am converting driver as a mouse device.
 mouse.Click(loc.Coordinates);    //Here driver click on that coordinates.


IWebElement element = driver.FindElement(By.XPath("//img[@name='jack']"));
new Actions(driver).MoveToElement(element).Perform();
ILocatable loc = (ILocatable)element;
IMouse mouse = ((IHasInputDevices)driver).Mouse;         // Converting driver as a Mouse
mouse.ContextClick(loc.Coordinates);                    //Right Click
IKeyboard key = ((IHasInputDevices)driver).Keyboard;    // Converting driver as a Keyboard
key.SendKeys("w");

Selenium TİMEOUT

driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromMinutes(10));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));            
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromMinutes(20));

Selenium linke tıklatma

IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl("http://www.google.com");

// find directly, note it's not in the <a> but in <span>
// driver.FindElement(By.XPath("//span[text()='YouTube']")).Click();

// your logic with LINQ
IList<IWebElement> links = driver.FindElements(By.TagName("a"));
links.First(element => element.Text == "YouTube").Click();

// your logic with traditional foreach loop
foreach (var link in links) {
    if (link.Text == "YouTube") {
        link.Click();
        break;
    }
}

driver.Quit();

Selenium Click İşlemleri

Seems like I have to use this line of code before I invoke any click events. The "clickAndWait" conversion of the Selenium IDE to Webdriver doesn't seem to work properly. It converts everything to *.Click(). Adding the implicit wait after every click event and setting WAIT_TIME to 3 in my Constants class seems to do the trick.
driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(Constants.WAIT_TIME));
driver.FindElement(By.LinkText("Products")).Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(Constants.WAIT_TIME));

24 Eylül 2014 Çarşamba

Resim exif kaldırmak 2

Resimden exif kaldırma

using System;
using System.IO;
using System.Windows.Media.Imaging;

namespace ExifRemover
{
public class ExifReader
{
public void SetUpMetadataOnImage(string filename)
{
string tempName = Path.Combine(Path.GetDirectoryName(filename), Guid.NewGuid().ToString());
// open image file to read
using (Stream file = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
// create the decoder for the original file. The BitmapCreateOptions and BitmapCacheOption denote
// a lossless transocde. We want to preserve the pixels and cache it on load. Otherwise, we will lose
// quality or even not have the file ready when we save, resulting in 0b of data written
BitmapDecoder original = BitmapDecoder.Create(file, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
// create an encoder for the output file
BitmapEncoder output = null;
string ext = Path.GetExtension(filename);
switch (ext)
{
case ".png":
output = new PngBitmapEncoder();
break;
case ".jpg":
output = new JpegBitmapEncoder();
break;
case ".tif":
output = new TiffBitmapEncoder();
break;
}

if (original.Frames[0] != null && original.Frames[0].Metadata != null)
{
// So, we clone the object since it's frozen.
BitmapFrame frameCopy = (BitmapFrame)original.Frames[0].Clone();
BitmapMetadata metadata = original.Frames[0].Metadata.Clone() as BitmapMetadata;

StripMeta(metadata);

// finally, we create a new frame that has all of this new metadata, along with the data that was in the original message
output.Frames.Add(BitmapFrame.Create(frameCopy, frameCopy.Thumbnail, metadata, frameCopy.ColorContexts));
}
// finally, save the new file over the old file
using (Stream outputFile = File.Open(tempName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
{
output.Save(outputFile);
}
}
File.Delete(filename);
File.Move(tempName, filename);
}

public void StripMeta(BitmapMetadata metaData)
{
for (int i = 270; i < 42016; i++)
{
if (i == 274 || i == 277 || i == 284 || i == 530 || i == 531 || i == 282 || i == 283 || i == 296) continue;

string query = "/app1/ifd/exif:{uint=" + i + "}";
BlankMetaInfo(query, metaData);

query = "/app1/ifd/exif/subifd:{uint=" + i + "}";
BlankMetaInfo(query, metaData);

query = "/ifd/exif:{uint=" + i + "}";
BlankMetaInfo(query, metaData);

query = "/ifd/exif/subifd:{uint=" + i + "}";
BlankMetaInfo(query, metaData);
}

for (int i = 0; i < 4; i++)
{
string query = "/app1/ifd/gps/{ulong=" + i + "}";
BlankMetaInfo(query, metaData);
query = "/ifd/gps/{ulong=" + i + "}";
BlankMetaInfo(query, metaData);
}
}

private void BlankMetaInfo(string query, BitmapMetadata metaData)
{
object obj = metaData.GetQuery(query);
if (obj != null)
{
if (obj is string)
metaData.SetQuery(query, string.Empty);
else
{
ulong dummy;
if (ulong.TryParse(obj.ToString(), out dummy))
{
metaData.SetQuery(query, 0);
}

}
}
}
}
}

Resim exif kaldırma

Resimden exif kaldırmak için gerekli c# kodları

namespace ExifRemover
{
  public class JpegPatcher
  {
    public Stream PatchAwayExif(Stream inStream, Stream outStream)
    {
      byte[] jpegHeader = new byte[2];
      jpegHeader[0] = (byte) inStream.ReadByte();
      jpegHeader[1] = (byte) inStream.ReadByte();
      if (jpegHeader[0] == 0xff && jpegHeader[1] == 0xd8)
      {
        SkipExifSection(inStream);
      }

      outStream.WriteByte(0xff);
      outStream.WriteByte(0xd8);

      int readCount;
      byte[] readBuffer = new byte[4096];
      while ((readCount = inStream.Read(readBuffer, 0, readBuffer.Length)) > 0)
        outStream.Write(readBuffer, 0, readCount);

      return outStream;
    }

    private void SkipExifSection(Stream inStream)
    {
      byte[] header = new byte[2];
      header[0] = (byte) inStream.ReadByte();
      header[1] = (byte) inStream.ReadByte();
      if (header[0] == 0xff && header[1] == 0xe1)
      {
        int exifLength = inStream.ReadByte();
        exifLength = exifLength << 8;
        exifLength |= inStream.ReadByte();

        for (int i = 0; i < exifLength - 2; i++)
        {
          inStream.ReadByte();
        }
      }
    }
  }
}