I have a selenium code trying to sendkeys()
I am using firefox 35.0.1 and selenium webdriver 2.44 and eclipse Luna
WebDriver d1 = new FirefoxDriver()
d1.get("www.xx.com")
WebElement username=d1.findElement(By.xpath(".//*[#id='login_username']/input"))
WebElement password=d1.findElement(By.xpath(".//*[#id='login-assword']/input"))
username.sendKeys("admin")
password.sendKeys("welcome")
This enters the values and deletes it before I submit the values.
tried adding
d1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS)
I've tried putting Thread.sleep(x);
but nothing is working please help me out.
Try using Thread.sleep after clicking into the text field and then do a sendKeys().
If that doesn't work, try waiting until the document is loaded entirely. See below function:
void waitForPageLoad(WebDriver driver)
{
ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>()
{
public Boolean apply(WebDriver driver)
{
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
wait.until(pageLoadCondition);
}
Related
im trying to make test in Eclipse, using Selenium and Firefox webdriver. I wrote next class:
public class Selenium {
FirefoxDriver driver;
#BeforeTest
public void setup(){
driver = new FirefoxDriver();
}
#Test
public void go_to(String url){
driver.get(url);
}
Now in my main class im trying do that:
String url = JOptionPane.showInputDialog("Please input where do you want to go");
selenium.setup();
report.start_report();
selenium.go_to(url);
But also, i want to write
if(selenium.driver.getStatus)
Is there any command, to take boolean value, from my driver.get(url)? For example, if successful go to web page, then true, and if error, then false?
user should be able to select the preferred language
and content of the web site should be loaded with the selected language using followng web site?
This is my current code how I Modify to match this scenario?
ublic class Steps {
WebDriver driver;
#Given("^Open the Firefox and launch the application$")
public void open_the_Firefox_and_launch_the_application() throws Throwable
{
System.setProperty("webdriver.gecko.driver", "E://Selenium//Selenium_Jars//geckodriver.exe");
driver= new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.gov.lk/welcome.html");
}
#Then("^Reset the credential$")
public void Reset_the_credential() throws Throwable
{
driver.findElement(By.name("btnReset")).click();
}
}
The element is a JavaScript enabled element so to click() on the element you need to use WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.english"))).click();
xpath:
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='english']"))).click();
I need a little help. I'm trying to run an automated test on the website http://zara.com and i want to select the language from the language dropdown.
This is the HTML code from Zara. https://prntscr.com/g6hdiv
This is the code i've tried with Selenium 2.53 in IntelliJ
public class RegistrationTest {
WebDriver driver;
#Before
public void setUp(){
driver = new FirefoxDriver();
driver.get("http://zara.com");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
#After
public void tearDown(){
driver.quit();
}
#Test
public void test(){
WebElement languageDropdown = driver.findElement(By.id("language"));
Select selectLanguage = new Select(languageDropdown);
selectLanguage.selectByValue("en");
}
}
I always receive the error below even if I've tried in different setups but it didn't work.
org.openqa.selenium.ElementNotVisibleException: The element is not currently visible and so may not be interacted with
Could you please tell me what am I doing wrong?
Appreciate the help.
The element is not currently visible and so may not be interacted with
You need to scroll the page, so that the element is in the current viewport. Something like this:
WebElement languageDropdown = driver.findElement(By.id("language"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", languageDropdown);
Select selectLanguage = new Select(languageDropdown);
selectLanguage.selectByValue("en");
I am Having a Lot of WebElements
For Example I Declared a WebElement a
#FindBy(id="BtnLogin")
private WebElement btnLogin;
In the Same Manner I created "N" number of WebElements
Every time I Cant use "driver.findElement()" function So I wrote a function
public static void WebElementClick(WebElement we)
{
we.click();
}
When Ever the Control is Going to The Line we.click() in the WebElementclick Function it is Showing NullPointerException as a Result My Purpose is Failing
I am Not Getting What to Do,Some One Please Help Me on this :)
Your WebElementClick should receive the selector and it should: find element -> click, you can get an example from the above link.
In your case you it seems that you are not using wait and the WebElementClick it tries to click on the string.
Using find will return an object that will make click available.
The method should contain something like: driver.findElement(By.xpath("your_selector"));
Ant then use click on what this method returns.You can use also css if you want to.
public class testJava{
#Test
public void testMethod() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
pageClass pageClass = PageFactory.initElements(driver, pageClass.class);
driver.get("http://www.facebook.com");
Thread.sleep(5000);
pageClass.clickLoginBtn();
}}
public class pageClass {
#FindBy(id = "loginbutton")
private WebElement loginBtn;
WebDriver driver;
public pageClass(WebDriver driver) {
this.driver = driver;
}
public void clickLoginBtn()
{
click(loginBtn);
}
public void click(WebElement we)
{
we.click();
}}
Its best practice to use the page class & test class..Try this it will help you i guess.
You are suppose to use driver to find & click the element.
I think that driver may try to click element before it's presented. Good practice before clicking WebElement is to wait for WebElement being clickable. I would try:
public static void WebElementClick(WebElement we)
{
wait.forElementClickable(we);
we.click();
}
My test script are developed using Java with Selenium webdriver api. There is 1 particular scenario where I need to click on a sub option loaded from a dropdown menu but I am not able to do that. Following are the test steps and the screenshot for the particular problem.
-Launch Microsoft Outlook Web App (OWA) and login
-On main screen I need to enter some text in Search Field
-Click the drop down next to it
-Select "This Folder" from the options loaded
(Screenshot)
I dont see any frameid so not using any. Dropdown works fine but failing to click on suboption.
Adding the code which I am using for click this
public static final By searchDropDown_locator= By.xpath(".//*[#id='divSScp']");
public static final By thisFolderText_locator= By.xpath("(.//*[#id='spnT' and text()='This Folder'])[2]");
public void clickSearchDropDown()
{
WebElement searchIcon= websitedriver.findElement(searchDropDown_locator);
searchIcon.click();
}
public void clickThisFolder()
{
WebElement searchIcon= websitedriver.findElement(thisFolderText_locator);
searchIcon.click();
}
I am calling both these functions in my script file.
What could be the solution here.
Try to use JavascriptExecutor for click as below
public void clickSearchDropDown()
{
WebElement searchIcon= websitedriver.findElement(searchDropDown_locator);
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", searchIcon);
}
public void clickThisFolder()
{
WebElement searchIcon= websitedriver.findElement(thisFolderText_locator);
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", searchIcon);
}
Hope it will help you :)