An issue when uploading CSV file using Selenide on Jenkins - selenium

Im trying to upload CSV file from local storage.
Driver initialization:
private static RemoteWebDriver createRemoteWebDriver(DesiredCapabilities caps) throws MalformedURLException {
RemoteWebDriver driver = new RemoteWebDriver(getBrowserstackURL(), caps);
driver.setFileDetector(new LocalFileDetector());
return driver;
}
Upload method:
public void uploadFileUniversal(String fileName, SelenideElement uploadAreaElement) {
uploadAreaElement.shouldBe(Condition.enabled, DefaultDuration.DEFAULT);
LocalFileDetector detector = new LocalFileDetector();
File localFile = detector.getLocalFile("src/test/resources/" + fileName);
uploadAreaElement.sendKeys(localFile.getAbsolutePath());
}
Page:
<span class="btn btn-default upload-csv"><span class="glyphicon glyphicon-upload"></span>
<span class="upload-btn-text">Import CSV</span>
<input id="select-upload-csv" type="file" name="select-upload-assets" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
</span>
CSV:
Slide,Time
1,00:10
2,00:15
3,00:20
As result, I have gotten a validation message from FE. An issue appears only using Jenkins, locally it works like a charm.

Related

We are unable to detect your camera while passing fake media to experitest chrome browser

I did not get a specific chrome option to work fine when my test is running on the server where we don't have a webcam when started chrome per the java selenium web driver script.
The goal is to mock a camera on the server and pass a fake media stream to the server machine where we don't have a webcam. The script is working fine on the local machine (because the local machine has a webcam) but it's not working on the experitest cloud browser where we don't have a webcam.
How to mock a camera on devices without a camera so that I can run my script through CI pipeline on a server or cloud browser?
The below code is working locally but not on the cloud browsers where we don't have support for the webcam and currently facing the we are unable to detect your camera error when running on a cloud browser
public class Sample {
private static final String ACCESS_KEY = "XXXX";
private RemoteWebDriver driver;
private URL url;
private DesiredCapabilities dc = new DesiredCapabilities();
#Before
public void setUp() throws Exception {
String videoSource = getClass().getClassLoader().getResource("sample1.y4m").toURI().toString();
System.out.println(videoSource);
ChromeOptions config = new ChromeOptions();
config.addArguments( //
"--use-fake-ui-for-media-stream", //
"--use-fake-device-for-media-stream", //
"--use-file-for-fake-video-capture=" + videoSource);
config.setHeadless(true);
config.setAcceptInsecureCerts(true);
dc.setCapability("testName", "Quick Start Chrome Browser Demo");
dc.setCapability("accessKey", ACCESS_KEY);
dc.setCapability(ChromeOptions.CAPABILITY, config);
dc.setCapability(CapabilityType.BROWSER_NAME, "chrome");
driver = new RemoteWebDriver(new URL("https://XXXXX/wd/hub"), dc);
}
#Test
public void virtualTryOn() {
driver.get("https://mytrialpage.com");
WebElement cookies = driver.findElement(By.id("onetrust-accept-btn-handler"));
cookies.click();
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//button[#id='virtualTryOn']")));
WebElement vto = driver.findElement(By.xpath("//button[#id='ctaVirtual']"));
vto.click();
driver.switchTo().frame("scan-iframe");
}
#After
public void tearDown() {
System.out.println("Report URL: "+ driver.getCapabilities().getCapability("reportUrl"));
driver.quit();
}
}
**
cloud browser output:
**

How to scrape JavaScript webpages using PhantomJS?

I am trying to Crawl this site and get the links of each Job posting. I am using the Selenium and PhantomJS to render the webpage, but I am not able to find the links in the rendered content. This is the script I am using
public static void main(String[] args) {
// TODO Auto-generated method stub
String url="https://www.paycomonline.net/v4/ats/web.php/jobs?clientkey=D25120971391831BA4315C705AA7ABF1&jpt=";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setPlatform(Platform.LINUX);
RemoteWebDriver driver = getRemoteDriver("http://localhost:9515", capabilities);
driver.manage().window().maximize();
driver.get(url);
new WebDriverWait(driver, 360)
.until(RemoteWebDriver -> ((JavascriptExecutor) RemoteWebDriver)
.executeScript("return document.readyState").equals("complete"));
byte[] content = driver.getPageSource().getBytes();
String html = new String(content);
System.out.println(html);
}
I am running PhantomJS in my local machine at port 9515.Can someone help?

could not be able to send keys to the username box in selenium

I have tried many times with different xpath and asked in different forums but didn't got the solution. Waiting for your help.
package chromedriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Espncom {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.gecko.driver","C:\\Selenium softwares\\geckodriver-v0.19.0-win64\\geckodriver.exe");
WebDriver driver= new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://www.espn.com/");
driver.findElement(By.linkText("Log In")).click();
//driver.findElement(By.xpath("//input[#placeholder='Username or Email Address']")).sendKeys("cricket");
driver.findElement(By.xpath(".//div/div/section/section/form/section/div[1]/
div/label/span[2]/input")).sendKeys("cricket");
}
}
HTML Code for username or email address:
<input placeholder="Username or Email Address" autocapitalize="none" autocomplete="on" autocorrect="off" spellcheck="false" ng-model="vm.username" ng-pattern="/^[^<">]*$/" ng-required="true" did-disable-validate="" ng-focus="vm.resetUsername()" class="ng-pristine ng-invalid ng-invalid-required ng-valid-pattern ng-touched" tabindex="0" required="required" aria-required="true" aria-invalid="true" type="email">
In Espn site, when you click login then it opens a frame. you need to switch to frame and then you need to try finding the email or name textbox.
try with the below code and update back
driver.switchTo().frame("disneyid-iframe");
driver.findElement(By.xpath("//input[#placeholder='Username or Email address']")).sendKeys("cricket");

Can not find password input object log in to google with selenium

I am using PhantomJS in selenium for the driver. Here, I find that there is no problem inserting the email address. However, after clicking the next, there should have a input tag named 'password'. But, after waiting, I can not get the required 'password' tag. It shows error not finding the element. Sometimes, I am getting the following error (showing stacktrace):
org.openqa.selenium.InvalidElementStateException: {"errorMessage":"Element is not currently interactable and may not be manipulated","request":{"headers":{"Accept-Encoding":"
Since, I have waited enough time, the following code must work.
Here is the below code snippet for working.
driver.get("https://accounts.google.com/ServiceLoginAuth");
driver.findElement(By.id("identifierId")).sendKeys("xxxxxxxx");
driver.findElement(By.id("identifierNext")).click();
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.name("password")));
driver.findElement(By.name("password")).sendKeys("xxxxxxxx");
driver.findElement(By.id("passwordNext")).click();
Here is the specific html showing the input field from the google sign in page for email:
input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="username" spellcheck="false" tabindex="0" aria-label="Email or phone" name="identifier" id="identifierId" dir="ltr" data-initial-dir="ltr" data-initial-value=""
The id of Next button is 'identifierNext' and hhe hidden password field:
input type="password" name="hiddenPassword" jsname="RHeR4d" class="yb9KU" tabindex="-1" aria-hidden="true"
After inserting email and click on the next, the input field for the password is:
input type="password" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="current-password" spellcheck="false" tabindex="0" aria-label="Enter your password" name="password" autocapitalize="off" autocorrect="off" dir="ltr" data-initial-dir="ltr" data-initial-value=""
Now, the question is, I have used waiting mechanism for reloading the page so that I can get the password insertion page. But, using Selenium I can not find the named tag of 'password'.
I think the click is not working properly. Is there any chance of not working the click on Next?
Try this:
driver.findElement(By.xpath("//input[1]"));
Or this:
WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[#type='password']")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[#type='password']")));
WebElement elementpwd = driver.findElement(By.xpath("//input[#type='password']"));
I hope it helps.
Please find the full code for sending email for Gmail using Selenium Web Driver using Chrome browser
public class Newtest {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Tharun\\Desktop\\work\\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.google.com");
driver.findElement(By.xpath("//*[#id='gb_70']")).click();
driver.findElement(By.xpath("//*[#id=\'identifierId\']")).sendKeys("*******#gmail.com");
driver.findElement(By.xpath("//*[#id=\'identifierNext\']/content/span")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//input[#type='password']")).sendKeys("*******");
driver.findElement(By.xpath("//*[#id=\'passwordNext\']/content/span")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id=\"gbw\"]/div/div/div[1]/div[2]/a")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id=':ir']/div/div")).click();
Thread.sleep(5000);
driver.findElement(By.cssSelector("#\\3a og")).sendKeys("*******#gmail.com");
driver.findElement(By.cssSelector("#\\3a ny")).sendKeys("This is my selenium web driver automation code ");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[#id=\':p3\']")).sendKeys("This is my selenium web driver automation code ");
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id=\':no\']")).click();
}
}

Selenium webdriver java - upload file with phantomjs driver

I am running a selenium webdriver script headless using Phantomjs Driver. I am having issues uploading a file though since on a normal browser (firefox or chrome) it would pop up the OS dialog box that would allow me to locate the file in my machine and upload it.
How to do that with the ghostDriver (Phantomjs Driver)?
Thanks
Always identify & interact with elements of type "file" when uploads are concerned. This would solve your issue of pop ups.
Ex: In my application, upload related elements have the below DOM -
<a id="uploadFileButtonLink" class="uploadFileButtonLink" href="javascript:void(0)" data-uidsfdc="3" style="display: none;">Upload a file</a>
<input id="multiFileInput" class="multifile-upload-input-button" type="file" name="chatterFile_upload" multiple="multiple"/>
<input id="multiUploadBtn" class="btnImportant" type="button" value="Upload Files"/>
In this case, you can use sendKeys method to "multiFileInput" which is of type "file".
This way it would work for all FF, Chrome & also headless browsers.
I am having the same issue and have posted a question for the same. PhantomJS hangs up when using sendKeys() method.
They have an issue logged here - https://github.com/ariya/phantomjs/issues/10993
One of the comments on the issue stated that the below statement worked -
(PhantomJSDriver) driver.executePhantomJS("var page = this; page.uploadFile('input[type=file]', 'path to file');");
You may try the above solution, but it may or may not work.
This code helped me with uploading if 'multiple' attribute was set:
protected void uploadFile(CharSequence... keys) {
if (((WrapsDriver) driver).getWrappedDriver() instanceof PhantomJSDriver) {
StringBuffer s = new StringBuffer(keys.length);
for (int index = 0; index < keys.length; index++) {
s.append(keys[index].toString());
}
((PhantomJSDriver) ((WrapsDriver) driver).getWrappedDriver()).executePhantomJS(
String.format("var page = this; page.uploadFile(arguments[0], '%s');", s.toString()), getElement());
} else {
getElement().sendKeys(keys);
}
}
var webPage = require('webpage');
var page = webPage.create();
page.uploadFile('input[name=image]', '/path/to/some/photo.jpg');
in the new version of phantomjs, you can upload file like this
uploadfile