Click on Captcha via Selenium always raised picture verification - c#

So i try to send SMS using this site via Selenium.
After choose my country and my phone number i have this Captcha:
So with Selenium i succeed to click on this Checkbox but allways got this image verification:
i try to put several sleeps before this Checkbox click but this image verification is still exist.
This behavior is not hapenning via manual scenarion so my question is why this is happening ?
This is how i am find my elements and click on Captcha Checkbox:
IWebElement frame = driver.FindElements(By.XPath("//iframe[contains(#src, 'recaptcha')]"))[0];
driver.SwitchTo().Frame(frame);
IWebElement checkbox = Driver.Browser.FindElement(By.CssSelector("div.recaptcha-checkbox-checkmark"));
checkbox.click();

This is the whole point of captcha's that bot do-not pass a certain point/crawl a webpage; This appears when a website is suspicious of bot activity so just to make sure that a human is on another side these images are shown; so that only a human can be allowed further activity.
You don't get these images when you try to do that manually is because you verify this on local installation of a browser, which have constantly saved cookies about your activities; but when you launch the same screen via Selenium WebDriver a new fresh instance is launched and to make sure that instance/session is legit; websites can ask for captcha details,
But in order to circumvent this situation, you can try to use same sessions where you have already answered the questions, you can do this using DesiredCapabilities in selenium, please google for more.

Take out side beyond selenium , use Sikuli http://www.sikuli.org/ to click on the button and do your stuff Use Java Api of Sikuli not the IDE and use relative region.
All though as mentioned above if you have the scope of the Dev also ,
speak with the Dev and turn off the Captcha from the flow

try logging into an old gmail account before attempting to click recaptcha automatically

import the sikuli jar into your project and use below code
package com.test;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
public class CaptchaCick{
public static void main(String[] args) throws FindFailed, InterruptedException {
// TODO Auto-generated method stub
Screen s=new Screen();
s.find("source.png");
s.click(("source.png");
System.out.println("Source image found");
}
}

Related

C# Selenium Chrome clicking link from default chrome home page

I'm trying to get Selenium to click on one of the most visited web links from the default Chrome web page.
The problem is that Selenium cannot find the element on the page and I think it has to do with the fact that a web page technically didn't get loaded. When you open up Chrome it has HTML elements there but the address bar is completely empty. I think possibly this is why Selenium can't find the link? The code is simple and finding the XPATH wasn't an issue. I just don't know if this is a function that Selenium will be able to do or not. I'm trying to do the click because the navigate() function will not work when I put in the proxy information due to the fact that Selenium doesn't have a built-in way to handle a proxy with username and password.
At the end of the day I'm trying to get the username/password box to pop up by clicking on the link. When I open the browser with Selenium programmatically and then manually click on the link the username/password box pops up. But I can't get Selenium to find the element to click on programmatically.
var did = driver.FindElement(By.XPath("//*[#id='mv-tiles']/a[1]"));
did.Click();
UPDATE 1:
I was able to find the element when taking into consideration the iframe but clicking still is an issue.
var frm = driver.SwitchTo().Frame("mv-single");
var did = frm.FindElement(By.XPath("//*[#id='mv-tiles']/a[1]"));
//did.Click(); <-- I can see it go to the element but nothing occurs
IJavaScriptExecutor js2 = (IJavaScriptExecutor) driver;
js2.ExecuteScript("arguments[0].click();", did);
The JavaScriptExecuter is able to click the element but Chrome blocks the redirect with the following message:
[21040:24704:1204/150143.743:ERROR:CONSOLE(1)] "Unsafe JavaScript attempt to initiate navigation for frame with URL 'chrome-search://local-ntp/local-ntp.html' from frame with URL 'chrome-search://most-visited/single.html?title=Most%20visited&removeTooltip=Don%27t%20show%20on%20this%20page&enableCustomLinks=1&addLink=Add%20shortcut&addLinkTooltip=Add%20shortcut&editLinkTooltip=Edit%20shortcut'. The frame attempting navigation is targeting its top-level window, but is neither same-origin with its target nor has it received a user gesture. See https://www.chromestatus.com/features/5851021045661696.
", source: (1)
FINAL UPDATE:
I gave up and decided to do the browser extension solution for proxies with passwords: https://stackoverflow.com/a/35293222/5415162
That list of "Most Recent Pages" is actually in an iframe, which is probably why Selenium can't find it. Try updating the selector to account for the iframe, or maybe add a wait clause to allow the iframe to finish loading.
Regardless of that solution, I don't think it will act any differently than just navigating to the target URL. So to fix your root problem have you tried setting the proxy details when creating the ChromeOptions?

How to open browser for signing in and get contents in C#

I am trying to get strings from HTML using regular expression and it works on local html file. Only thing I need is to login on website using my program to get html from there.
The problem is that I tried logging in using 3 different codes without luck (I FOUND AL 3 CODES HERE). Website is HTTPS and also has no support for Internet Explorer. Don't want to use fiddler or any debugging tool. I don't care for speed, just want simple browser opening, signing in and getting html code from displayed content.
Is there any way to open chrome/mozilla/opera and transfer displayed HTML to my program? Or, if it's impossible, is there any some kind of universal way for signing in?
Is there any way to open chrome/mozilla/opera and transfer displayed HTML to my program?
You could use for example Selenium WebDriver for this. It will allow you to automate button pushing, text inputting etc. on the target web page. I wouldn't call it a "debugging tool", it's more like a testing framework. NuGet has all the packages you need:
Selenium WebDriver
Selenium WebDriver Support Classes
There is a really neat usage sample here:
// Initialize the Chrome Driver
using (var driver = new ChromeDriver())
{
// Go to the home page
driver.Navigate().GoToUrl("https://yourdomainhere.net");
// Get the page elements
var userNameField = driver.FindElementById("username");
var userPasswordField = driver.FindElementById("password");
var loginButton = driver.FindElementByXPath("//input[#value='Login']");
// Type user name and password
userNameField.SendKeys("admin");
userPasswordField.SendKeys("12345");
// and click the login button
loginButton.Click();
// Extract the text and save it into result.txt
var result = driver.FindElementByXPath("//div[#id='case_login']/h3").Text;
File.WriteAllText("result.txt", result);
}
I am trying to get strings from HTML using regular expression
I have small hunch that you.. shouldn't. You can use the driver to extract the data you want from the page.

How to type in a field and click a button on a site that I navigated to

I was able to navigate to my desired site using the following code
System.Diagnostics.Process.Start("https://www.google.com/");
How can I provide an input from a variable that I declared in CodeBehind? After that, I am planning to click the button and then further use the data.
Basically, my problem is about controlling the elements that are found in the site that I navigated to using C#.
Thank you very much!
Use Selenium. You can download the NuGet package from here. Below is some code which goes to gmail and then finds the email textbox and types some text into in. It then presses a button.
Driver.Navigate().GoToUrl("https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1");
Driver.FindElement(By.Id("Email")).SendKeys("myEmail"); // Type email
Driver.FindElement(By.Id("next")).Click(); // Click the button
Driver.FindElement(By.Id("Passwd")).SendKeys("myPass");
Also download the chromedriver from here and put the .exe file in your bin folder. Selenium will pick it from there and use it. You can use any web driver.
EDIT
To open a new tab:
IWebElement body = driver.FindElement(By.TagName("body"));
body.SendKeys(Keys.Control + "t");

Inserting text from a C# WinForms application into a web browser textbox

I'm currently working on a WinForms application that I'm hoping will allow users to enter stored passwords into a web browser without a keylogger being able to see the password. I've got the storing part completed, but I can't figure out how to insert the password into a browser without using either the clipboard or .NET's SendKeys class, both of which can be seen by most keyloggers.
I looked into using Windows messages to do this, but, from what I understand, you need to know the hWnd of a control in order to send it a Windows message. Unfortunately, it appears that web browsers do not use hWnds for individual textbox controls.
I know there has to be a way to do this. In Notepad++, for example, you can drag text into a web browser textbox and the text doesn't show up in keyloggers. Same goes for Neo's SafeKeys. Anyone have any ideas on a general approach to doing this? Thanks so much.
What you want is a WebDriver Library. Unfortunately .net does not have plenty of good ones. You can take a look at WatiN or selenium
From what I understand watin isn't supported anymore and is not multi-browser compatible.
Here is an example of what you can do with selenium
using (var driver = new ChromeDriver())
{
driver.Navigate().GoToUrl("http://testing-ground.scraping.pro/login");
var userNameField = driver.FindElementById("usr");
var userPasswordField = driver.FindElementById("pwd");
var loginButton = driver.FindElementByXPath("//input[#value='Login']");
userNameField.SendKeys("admin");
userPasswordField.SendKeys("12345");
loginButton.Click();
}
I image you can link your driver to an existing opened browser
If you are able to run ruby on the computers I would recommend using Watir
and running the ruby script doing the web manipulation from the c# using processes.

How to launch a browser and later direct it to a page?

I need to launch a browser, do some work and then make the browser navigate to a URL (in that order).
The first part is of course simple and I have a Process object. I am at a loss as to how to later direct it to the target page?
How do I treat the Process as a browser and make it navigate to the desired page?
Any help, pointers, code snippets appreciated.
Instead of launching the browser & then navigating to the page, just tell the OS that you want to run the URL. Windows will pick the correct browser, and navigate the user to the given URL.
System.Diagnostics.Process.Start("http://www.StackOverflow.com");
If you don't need to do this in production, you could use a testing library such as WatiN to do this:
using WatiN.Core;
//Placeholder page to launch initial browser
IE ie = new IE("http://www.google.com");
DoSomeWork();
//Now navigate to the page you want
ie.GoTo("http://stackoverflow.com");
My first instinct for this question was DDE, but it appears that has been decommissioned in Windows Vista so that is no good. Shame, as it was the only consistent mechanism in Windows for Interprocess Communication (IPC)...oh how I miss Arexx on the Amiga.
Anyhow, I believe the following will work but unfortunately, due to the way it works, it launches Internet Explorer irrespective of the configured browser.
If your application has a Form, then create a WebBrowser control on it. Set this to non-visible as we are only making use of its as a launching device rather than to display the web page.
In code, at the point where you want to show a web page, use the following code:
webBrowser1.DocumentText = "window.open('How to launch a browser and later direct it to a page?', 'BananasAreOhSoYummy');";
What this does is to tell the WebBrowser control, which is just the IE in disguise, to open a new window called 'BananasAreOhSoYummy'. Because we have given the window a name, we can use that line repeatedly, with different URLs, to change the page in that particular browser window. (A new window will be opened if the user has happened to close it.)
I will have a think about an approach that honours the user's default browser choice.
If you don't need the actual instance of IE, you can use the System.Windows.Forms.WebBrowser control.
I think instead of sending the browser a url you could send it javascript that would run and direct the browser to a site.
Not sure if this would work but I see no reason why it wouldn't

Categories

Resources