selenium webdriver : input data NOT inserted - selenium

Below is a text input box Search for
in selenium, i can first find the element, input data. but on the front end i dont see any data inputted
I am not sure why my UI doesnt show data being typed by the webdriver . no error in the code log
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\rahul\\Downloads\\chromedriver_win32_83\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("http://testingapp.workspez.com");
driver.manage().window().maximize();
WebElement username = driver.findElement(By.id("field_email"));
WebElement password = driver.findElement(By.id("field_password"));
WebElement login = driver.findElement(By.xpath("//*[text()='Log In']"));
username.sendKeys(Keys.CONTROL + "a");
username.sendKeys(Keys.DELETE);
password.sendKeys(Keys.CONTROL + "a");
password.sendKeys(Keys.DELETE);
username.sendKeys("rahul#workspez.com");
password.sendKeys("Sujeet#19");
login.click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement generalInfo = driver.findElement(By.xpath("//*[text()='General Info']"));
generalInfo.click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
WebElement Contacts = driver.findElement(By.xpath("//*[text()='Contacts']"));
Contacts.click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//find search for
WebElement newlyaddedcontact1 = driver.findElement(By.xpath("//*[text()='Search for']"));
JavascriptExecutor executor1 = (JavascriptExecutor) driver;
executor1.executeScript("arguments[0].click();", newlyaddedcontact1);
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].value='searchcontact';", newlyaddedcontact1);
WebElement search = driver.findElement(By.xpath(".//*[#class='MuiButtonBase-root MuiIconButton-root']"));
search.click();
how to access that webpage
1.login into http://testingapp.workspez.com
username :rahul#workspez.com password: Sujeet#19
click general info tab on top, then click contacts 'tab'
you will see the search for box.

I thing You need to change you Xpath.Because whatever you write XPath this is for a label you need to write for input control so i update your code.
IWebElement newlyaddedcontact1 = driver.FindElements(By.XPath("//input[contains(#class,'MuiInput-input')]")).ToList()[0];
JavascriptExecutor executor1 = (JavascriptExecutor) driver;
executor1.executeScript("arguments[0].click();", newlyaddedcontact1);
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].value='"+name+"';", newlyaddedcontact1);
Please Try this code. I write in C# language.

Related

Drag and drop in Selenium

In https://www.globalsqa.com/demo-site/draganddrop/ I need to drag and drop picture with the text "High Tatras" into Trash section.
#Test
void task1() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\DELL\\Desktop\\New folder\\chromedriver.exe");
WebDriver webDriver = new ChromeDriver();
try {
webDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
webDriver.get("https://www.globalsqa.com/demo-site/draganddrop/");
WebElement from = webDriver.findElement(By.xpath("//*[#id=\"gallery\"]/li[1]"));
WebElement to = webDriver.findElement(By.xpath("//*[#id=\"trash\"]"));
Actions actions = new Actions(webDriver);
actions.dragAndDrop(from, to).build().perform();
} finally {
webDriver.close();
}
}
Both the from and to elements are inside the iframe.
So, to access these elements you need to switch into that iframe first.
Your code will look as following:
#Test
void task1() {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\DELL\\Desktop\\New folder\\chromedriver.exe");
WebDriver webDriver = new ChromeDriver();
try {
webDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
webDriver.get("https://www.globalsqa.com/demo-site/draganddrop/");
driver.switchTo().frame(driver.findElement(By.xpath("//div[#rel-title='Photo Manager']//iframe")));
WebElement from = webDriver.findElement(By.xpath("//*[#id='gallery']/li[1]"));
WebElement to = webDriver.findElement(By.xpath("//*[#id='trash']"));
Actions actions = new Actions(webDriver);
actions.dragAndDrop(from, to).build().perform();
} finally {
webDriver.close();
}
}

why i am getting this exception? Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException:

i am trying to login into flipkart by providing login id and password.here is the code.but i am getting this exception.
Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element ... is not clickable at point (657, 27). Other element would receive the click: ...
public class Selanium {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.get("https://www.flipkart.com/");
driver.findElement(By.className("_3Ep39l")).click();
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath("//input[#class='_2zrpKA _1dBPDZ']")));
Thread.sleep(1000);
actions.click();
actions.sendKeys("arfatjaya#gmail.com");
Thread.sleep(1000);
actions.build().perform();
actions.moveToElement(driver.findElement(By.className("_2zrpKA _3v41xv _1dBPDZ")));
Thread.sleep(1000);
actions.click();
actions.sendKeys("sfghghyy56cgc#");
Thread.sleep(1000);
actions.build().perform();
actions.moveToElement(driver.findElement(By.xpath("//button[#class='_2AkmmA _1LctnI
_7UHT_c']")));
Thread.sleep(1000);
actions.click();
}
}
Trying using JavascriptExecutor:
//Creating the JavascriptExecutor interface object by Type casting
JavascriptExecutor js = (JavascriptExecutor)driver;
//Perform Click on WebElement using JavascriptExecutor
js.executeScript("arguments[0].click();", webElement);
Note: Please add below import in your code.
import org.openqa.selenium.JavascriptExecutor;

Unable to select drop-down list item on Google's Advance Search page

Issue :
Unable to select the language from the drop-down list.
Please help!!
Test Steps:
Go to https://www.google.co.in/
Click 'Settings' present at bottom right.
Now click 'Advance Search'
Advance search page will be opened.
Click a drop-down whose name is 'any language'.
Drop-down list of languages will be opened.
Select any language from drop-down list say Hindi.
Code is as follows:
public class DropDown_Settings {
static String baseURL = "https://google.com";
static WebDriver driver;
public static void main(String[] args) throws InterruptedException
{
driver= new FirefoxDriver();
driver.get(baseURL);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[#id='fsettl']")).click();
driver.findElement(By.xpath(".//*[#id='advsl']/a[text()='Advanced
search']")).click();
driver.findElement(By.cssSelector("#lr_button")).click();
WebElement dropDown=driver.findElement(By.id("lr_menu"));
List<WebElement> options=dropDown.findElements(By.tagName("li"));
System.out.println(options.size());
for(WebElement value:options){
if(value.getText().equals("Hindi")){
System.out.println(value.getText());
value.click();
break;
}
}
}
}
Your code works fine in Chrome, Try this code it is working in both Firefox and chrome
Try this code in Firefox and Chrome:
System.setProperty("webdriver.chrome.driver","E:/software and tools/chromedriver_win32/chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.google.co.in/");
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
driver.findElement(By.xpath(".//*[#id='fsettl']")).click();
driver.findElement(By.xpath(".//*[#id='advsl']/a[text()='Advanced search']")).click();
driver.findElement(By.cssSelector("#lr_button")).click();
WebElement dropDown=driver.findElement(By.id("lr_menu"));
List<WebElement> options=dropDown.findElements(By.tagName("li"));
System.out.println(options.size());
for(int i=0;i<options.size();i++){
String langName=options.get(i).getText();
if(langName.contains("Hindi"))
{
options.get(i).click();
break;
}
}
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.google.co.in/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//a[#id='fsettl']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//span[#id='advsl']//a")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("//div[#id='lr_button']")).click();
driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
driver.findElement(By.xpath("//ul[#id='lr_menu']//li[23]")).click();
}

How to select Birthday(Month) drop down in the gmail registration page by Selenium Webdriver?

This is my code but its not select the value
WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default");
Thread.sleep(3000);
driver.findElement(By.xpath(".//*[#class='goog-inline-block goog-flat-menu-button jfk-select']")).click();
Thread.sleep(3000);
List<WebElement>menu=driver.findElements(By.xpath(".//*[#class='goog-menuitem-content']"));
Thread.sleep(3000);
for(int i=0;i<menu.size();i++){
WebElement element=menu.get(i);
String innerhtml=element.getAttribute("innerHTML");
if(innerhtml.contentEquals("April"))
{
element.click();
break;
}
System.out.println("value of dropdown "+innerhtml);
}
driver.quit();
try the following code:
driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default");
Thread.sleep(3000);
driver.findElement(By.xpath("//span[#id='BirthMonth']")).click();
Thread.sleep(3000);
driver.findElement(By.xpath("//div[#class='goog-menuitem-content' and text()='April']")).click();
Thread.sleep(3000);
I hope you did a setProperty for the gecko driver, in case, you're using Firefox browser.
Try this code after that point:
WebDriver driver= new FirefoxDriver();
driver.get("https://accounts.google.com/SignUp?hl=en");
driver.findElement(By.xpath(".//*[#id='BirthMonth']/div[1]")).click();
//Thread.sleep(3000);
List<WebElement> months= driver.findElements(By.xpath("//*[#role='option']")); //xpath of the list as a whole
System.out.println(months.size());
for(WebElement obj : months)
{
System.out.println(obj.getText());
if(obj.getText().contains("August"))
{
obj.click();
}
}
Hope, this works for you.

To perform Autosuggestion using Selenium

Having some problem in selecting the option from the dropdown using autosuggestion. Please give a solution to select the option.
The related code is posted below :-
#Test(priority = 4)
public void ReportType() throws InterruptedException {
WebElement reporttype = driver.findElement(By.xpath("html/body/form/div[3]/table[2]/tbody/tr[3]/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span/table/tbody/tr[3]/td[2]/span/table/tbody/tr/td[2]/input[1]"));
reporttype.clear();
reporttype.sendKeys("NMQ De");
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/form/div[3]/table[2]/tbody/tr[3]/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span/table/tbody/tr[3]/td[2]/span/div/ul/li[4]")));
Thread.sleep(5000);
driver.findElement(By.xpath("html/body/form/div[3]/table[2]/tbody/tr[3]/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/div/span/table/tbody/tr[3]/td[2]/span/div/ul/li[4]")).click();
}
Think your question as google search when u do some google search google provides u auto suggestion
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
String textToSelect = "headlines today";
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
Thread.sleep(2000);
WebElement autoOptions= driver.findElement(By.id("lst-ib"));
autoOptions.sendKeys("he");
List<WebElement> optionsToSelect = driver.findElements(By.xpath("//div[#class='sbqs_c']"));
for(WebElement option : optionsToSelect){
System.out.println(option);
if(option.getText().equals(textToSelect)) {
System.out.println("Trying to select: "+textToSelect);
option.click();
break;
}
}