Selenium can't aviod detection with webdrive - java

I have tested every method but still can't pass the block some reason. Not even trying to automate anything. Example page URL. I can access main page but can't access any link inside the web site with webdriver.
Java Code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-blink-features");
options.addArguments("--disable-blink-features=AutomationControlled");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
WebDriver driver=new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://www.sahibinden.com/ilan/hayvanlar-alemi-aksesuarlar-buyukbas-kucukbas-10x60-hayvan-yasam-alani-600metrekare-706539205/detay");

It worked with firefox driver + useragent + enabling javascript. I think I had some version issues on google driver.

Related

How to enable vpn in opera browser when selenium script is executed usingjava

System.setProperty("webdriver.opera.driver", "C:\folderNmae\operadriver.exe");
WebDriver driver = new OperaDriver();
Please add any information to do.

How to use already opened browser in webdriver using java

I have requirement that everytime i login, it asking security code in webapp. But it will ask only once since browser stored the cookies.but it is asking again and again in selenium webdriver since driver always opening new browser every time.
So i need to use already opened browser in selenium webdriver java. please help me with example code.
Finally i found solution that using google chrome option in java. It stores cookies in your temp file and reusing it everytime.
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("start-maximized");
options.addArguments("user-data-dir=D:/temp/");
capabilities.setCapability("chrome.binary","res/chromedriver.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY,options);
driver1 = new ChromeDriver(capabilities);

How to implement the selenium on public browser

WebDriver driver=new FirefoxDriver();
It automatically open the Private firefox browser. Is there any option to open normal browser instead of Private browser.
Not without some serious work on your end. When you create a new WebDriver instance, a firefox instance is started that uses no user profiles. It's like a fresh installation. WebDriver installs a profile on this clean browser instance and installs an extension that runs a little micro web server that listens for instructions from your java program. This little server is what enables two way communication between the browser's javascript environment and your remote java program.
The relationship between the running instance of this firefox web server extension and the WebDriver instance running in your java program is a tightly controlled partnership. It's not part of their criteria to allow you to do what you're asking, so you would have to venture far outside the boundaries of what they support.
You can directly invoke the browser without giving setProperty in firefox for selenium versions <3.0
Firefox in Selenium 3
System.setProperty("webdriver.gecko.driver","path of the driver");
WebDriver driver = new FirefoxDriver();
Replace webdriver.gecko.driver with webdriver.firefox.marionette if above doesn't work.
Chrome browser
System.setProperty("webdriver.chrome.driver", "path of the driver");
WebDriver driver=new ChromeDriver();
IE browser
System.setProperty("webdriver.ie.driver","path of the driver");
WebDriver driver=new InternetExplorerDriver();
Headless Browser
WebDriver driver = new HtmlUnitDriver();

Enabling popup windows in Chrome by Selenium

My apologies in advance if my question sounds primary, I am very new at QA and Selenium.
I am using Java and Selenium to write a test, at one of my test's step when I click on a button it is supposed to open another window but Chrome blocks the popup window, can I enable popup by Selenium?
Well, you need to initialize the ChromeDriver with a customized configuration which will disable the flag to block popups. From this site, the command line switch for it is disable-popup-blocking. So, using ChromeOptions and DesiredCapabilities, you add the desired config using the DesiredCapabilities.setCapability() function.
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("disable-popup-blocking");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
EDIT: Just found the same solution on this site.
There is also another option to enable popup windows. Because sometimes your company may block you from accessing any application in admin mode. If the above method fails to work, you can use the below codes to enable pop ups.
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("chrome://settings/content");
Thread.sleep(4000);
driver.switchTo().frame("settings");
Thread.sleep(2000);
driver.findElement(By.xpath("//input[#type='radio' and #name='popups']")).click();
Thread.sleep(4000);
driver.findElement(By.id("content-settings-overlay-confirm"));
Thread.sleep(4000);
Use the above code before starting your test.
If anyone is still encountering this problem, it's probably because they are on an old version of ChromeDriver. Popup blocking was disabled by default from version 21+
Reference: https://bugs.chromium.org/p/chromedriver/issues/detail?id=1291
For me worked this solution:
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-web-security");
ChromeDriver driver = new ChromeDriver(options);

PDF is not being opened in Chrome started by Selenium

I am using Selenium and ChromeDriver 2.43.1 with the latest Chrome (Version 42.0.2311.135 at the time the quetion was asked). My web application generates a PDF. It is being sent with the correct MIME type and it also correctly opens in the Chrome PDF viewer. However when I try to open the PDF using Selenium in Chrome that is started by the WebDriver, it gets downloaded.
I believe it might be some settings that Selenium or WebDriver use to start Chrome.
I've tried settings a few switches, but nothing worked yet. My code:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.addArguments("--please-make-it-work"); // not a real switch
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
webDriver = new ChromeDriver(capabilities);
webDriver.get(url);
What I really need is to start the browser in "normal" mode. It doesn't need any profile settings, just the defaults that will open the PDF.
The problem was caused by the recent change to the behaviour of the --test-type switch. It is described in the ChromeDriver issue tracker.
The workaround is to disable this switch. Here's my code changed:
// Add ChromeDriver-specific capabilities through ChromeOptions.
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
webDriver = new ChromeDriver(options);
webDriver.get(url);

Categories

Resources