Firefox webdriver is working where as Phanthon Js is not - java

The below script is working in firefox but doesn't work in Phanthon Js
driver.manage().window().maximize();
// Enter UserName
driver.findElement(By.xpath(".//*[#type='text']")).sendKeys("admin");
// Enter Password
driver.findElement(By.xpath(".//*[#type='password']")).sendKeys(
"admin");
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Click on 'Sign In' button
driver.findElement(By.xpath(".//button[#type='button']")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
WebElement webElement = driver.findElement(By.xpath("//button[contains(text(),'OK')]"));
webElement.click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//span[contains(text(),'Process')]"))
Error
Caused by: org.openqa.selenium.NoSuchElementException:
{"errorMessage":"Unable to find element with xpath
'.//span[contains(text(),'Process')]'","request":{"headers":{"Accept-
Encoding":"gzip,deflate","Connection":"Keep-Alive","Content-
Length":"60","Content-Type":"application/json; charset=utf-
8","Host":"localhost:32339","User-Agent":"Apache-HttpClient/4.4.1
(Java/1.8.0_60)"},"httpVersion":"1.1","method":"POST","post":".......
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Why Phanthon JS refused to work when it works fine using firefox web driver?
How to run the program headless i.e without browser which has the compatability with firefox webdriver code?
Alternative way to quickly prepare a script for headless?

Related

ChromeDriver with Selenium displays a blank page

I am using Selenium(Java) with Chrome to access the following website:
https://www.ebay-kleinanzeigen.de/m-einloggen.html?targetUrl=/
The Problem is that it always displays a blank page. Here is my Code:
ChromeOptions cap = new ChromeOptions();
cap.setBinary("C:\\Program Files (x86)\\Google\\Chrome Beta\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver","C:\\Users\\Admin\\Downloads\\chromedriver_win32beta\\chromedriver.exe");
WebDriver driver=new ChromeDriver(cap);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
try {
driver.get("https://www.ebay-kleinanzeigen.de/m-einloggen.html?targetUrl=/");
}catch(Exception e){
System.out.println(e);
}
Every other website I have tried works just fine, but this one doesn't want to show up. I have tried to access this website from Firefox, Chrome and Edge, which also show a blank page. I am using Selenium(3.141.59), ChromeDriver(81.0.4044.20) and Chrome Beta(81.0.4044.62).
Here is the HTML Code when I ispect the website:
It looks like this site can detect Selenium and do not open with it.
You can hide it using Chrome Options. Try adding arguments like this before openning the url:
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-blink-features=AutomationControlled");
ChromeDriver driver = new ChromeDriver(options);
Hope this helped, good luck!
It works with selenium stealth and the following options
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
I experienced the same issue. Check if the page you requested returns a successful HTTP status code like 200. In my case, it returned a 40x error which resulted in a blank page.

Cant select option from dropdown which is inside iframe - selenium - java8

I am trying to select option from the drop down in iframe but it is not getting selected.
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://verify-taxcerts.floridarevenue.com");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.switchTo().frame(driver.findElement(By.id("ivuFrm_page0ivu3")));
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(By.id("OFFM.SellerVerView.TaxTypeDDKey")).click();
driver.findElement(By.id("OFFM.SellerVerView.TaxTypeDDKey")).sendKeys("Sales and Use Tax");
Error
org.openqa.selenium.NoSuchElementException: Unable to locate element: #OFFM\.SellerVerView\.TaxTypeDDKey
Use case : i am trying to select option "sales and Use Tax"
what i am doing wrong ?
selenium version :3.14
ff : 70
Thanks
There's one more frame with isolatedWorkArea id:
driver.switchTo().frame(driver.findElement(By.id("ivuFrm_page0ivu3")));
// one more iframe
driver.switchTo().frame(driver.findElement(By.id("isolatedWorkArea")));
driver.findElement(By.id("OFFM.SellerVerView.TaxTypeDDKey")).click();

Error on uploading file using webdriver in firefox

To upload image on the field in this URL: http://demoqa.com/registration/
I used the following code that works on chrome but not on Firefox. May I please know the reason and solution?
WebDriver driver;
System.setProperty("webdriver.gecko.driver","C:\\Users\\abc\\Desktop\\Selenium\\geckodriver-v0.17.0-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://demoqa.com/registration/");
WebElement elementUpload=driver.findElement(By.xpath("//*[#id='profile_pic_10']"));
WebDriverWait wait=new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(elementUpload));
elementUpload.sendKeys("D:\\roboraid.jpg");
Error shown here is:
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: File not found: C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg
try this code with xpath with Explicit wait:
WebDriver driver = new FirefoxDriver();
driver.get("http://demoqa.com/registration/");
driver.manage().window().maximize();
WebElement elementUpload=driver.findElement(By.xpath("//*[#id='profile_pic_10']"));
WebDriverWait wait=new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(elementUpload));
elementUpload.sendKeys("D:\\1504857398686.png");
Please find output image:
try replacing spaces in the file location
from
C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg
to
C:\Users\Public\Pictures\Sample_Pictures\Chrysanthemum.jpg
Hope this works
Change the xpath to the below one and try. It worked for me.
//input[#name='profile_pic_10' and #type='file']
May I know the browser and environment details which you have tried?
Actually it was the issue with geckodriver of firefox
refer :-
https://github.com/mozilla/geckodriver/issues/659
You need to update your geckodriver
OR
Use chromedriver as below
System.setProperty("webdriver.chrome.driver", "D:\\Workspace\\StackOverlow\\src\\lib\\chromedriver.exe");
WebDriver driver = new ChromeDriver( );
driver.get("http://demoqa.com/registration/");
driver.manage().window().maximize();
((JavascriptExecutor) driver).executeScript("scroll(0,300)");
WebElement elementUpload=driver.findElement(By.xpath("//*[#id='profile_pic_10']"));
WebDriverWait wait=new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(elementUpload));
elementUpload.sendKeys("D:"+File.separator+"22.jpeg");

Not able to click on a button in selenium webdriver

webDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.xpath("html/body/div[1]/section[1]/div/div/a/button")).submit();
'View positions' button is not clicking with the above code.What is happening in the web page?
You see the HTML for this page is
So, you can use the CSS selector for this as
WebDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();
Thread.sleep(2000);
driver.findElement(By.cssSelector("button.button.teal").click();
And then proceed with doing whatever is necessary. I executed with this in my Python code and it works fine.
Also, you will need to provide the Gecko executable path while calling for the FirefoxDriver()
The way I have done it before is to use the click handler.
driver.findElement(By.cssSelector(".profile-actions .primary_button > span")).click();
I'm sure you could also select the element by xpath rather than CSS in the above line. It's a similar question to this one.

Upload file using selenium web driver

I have already check and search for same question and there are lot of solution but no one is working for me so posing question here.
I am doing practice of selenium web driver. I am using this form for practice : http://www.toolsqa.com/automation-practice-form/
Now , I have 3 issues in that.
1 - There are first 2 links called "Partial link test" & "List test" which I am able to click on, using "findelement", but I want to open both link in NEW TAB in same browser.
2 - I am not able to upload file. My code is not working for that element.
3 - How can I select particular value from dropdown of "Continents"??
My code is given below :
WebDriver driver = new FirefoxDriver();
driver.get("http://www.toolsqa.com/automation-practice-form/");
driver.manage().window().maximize();
**driver.findElement(By.linkText("Partial Link Test")).click();
driver.findElement(By.linkText("Link Test")).click();**
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.name("firstname")).sendKeys("Tester");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.name("lastname")).sendKeys("Tester");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("sex-0")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("exp-2")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("datepicker")).sendKeys("01/01/1985");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("profession-1")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
**driver.findElement(By.id("photo")).sendKeys("C:/Users/Public/Pictures/Sample Pictures/Desert.jpeg");**
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(600);
driver.findElement(By.id("tool-0")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
**driver.findElement(By.id("continents")).click();**
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Please help to correct my code.
I have added the answers inline to each of your questions, below. Also, an advice, is to use Implicit wait only once at the top while creating a browser instance, as its scope is the whole class itself. So, once declared, then selenium will wait a maximum of that time, for detecting an element. It can be rather overridden by using Explicit waits for certain elements, if necessary Please see this link for better understanding Implicit and Explicit waits:
1 - There are first 2 links called "Partial link test" & "List test" which I am able to click on, using "findelement", but I want to open both link in NEW TAB in same browser.
//Clicking and opening Partial Link Text in new tab
WebElement element = driver.findElement(By.linkText("Partial Link Test"));
Actions act = new Actions(driver);
act.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();
//Clicking and opening Link Text in new tab
element = driver.findElement(By.linkText("Link Test"));
act.contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ENTER).build().perform();
2 - I am not able to upload file. My code is not working for that element.
The path of the file must be like this:
driver.findElement(By.id("photo")).sendKeys("C:\\Users\\Public\\Pictures\\Sample Pictures\\Desert.jpg");
3 - How can I select particular value from dropdown of "Continents"??
You can use Select class for that like below. It will select the option "Australia".
Select sel = new Select(driver.findElement(By.id("continents")));
sel.selectByVisibleText("Australia");
Open link in new Tab:
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab);

Categories

Resources