I am trying to click on a line under the text but its not clicking on it and also not showing error.
website name voylla.com
package newpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.interactions.Actions;
public class seven {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "E:\\h\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "http://www.voylla.com";
driver.get(baseUrl);
WebElement menu = driver.findElement(By.className("dropdown"));
//WebElement submenu = driver.findElement(By.cssSelector("#main-div > div.mdl-tabs.mdl-js-tabs.mdl-js-ripple-effect.mdl-js-ripple-effect--ignore-events.is-upgraded > div > div > div > div:nth-child(7)"));
WebElement sub = driver.findElement(By.xpath("//*[#id=\"main-div\"]/div[2]/div/div/div/div[7]/a"));
Hover(driver, menu);
HoverAndClick(driver, sub, sub);
}
public static void Hover(WebDriver driver, WebElement element) {
Actions action = new Actions(driver);
action.moveToElement(element).perform();
}
public static void HoverAndClick(WebDriver driver, WebElement elementToHover, WebElement elementToClick) {
Actions action = new Actions(driver);
action.moveToElement(elementToHover).click(elementToClick).build().perform();
}
}
Related
I try to test this website https://classpad.net/classpad/use-as-guest using Selenium. I do not know how to make the form to select visible. Please see pictures below for more detail.
[Before I click on blank area]
[After I click]
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class DriverScript {
public static WebDriver driver;
public static WebElement element;
public static void main(String[] args) {
driver = new FirefoxDriver();
driver.navigate().to("http://34.201.210.27/classpad");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.findElement(By.xpath("/html/body/div/div[2]/form/a[2]")).click();
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.presenceOfElementLocated(By.className("scratchpaper-detail")));
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript("$('.scratchpaper-detail .stickyContainer .inputForm').show()");
String element = driver.getTitle();
System.out.println(element);
}
}
Mouse Over issue_Error Message_Can't convert from void to WebElement.
Showing the "Can't convert from void to WebElement" at WebElement creation line.
Attached screenshot.
My Code:
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import[enter image description here][1] org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
public class webelements2 {
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.gecko.driver","C:\\Users\\rpremala003\\Downloads\\geckodriver-v0.14.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.carmax.com/");
Actions builder = new Actions(driver);
WebElement menuElement = driver.findElement(By.linkText("CARS FOR SALE")).click();
builder.moveToElement(menuElement).build().perform();
driver.findElement(By.linkText("Buying from CarMax")).click();
}
}
.click() doesn't return an element and you are trying to assign the .click() result into a WebElement. Just remove the .click() and it should work without error.
WebElement menuElement = driver.findElement(By.linkText("CARS FOR SALE")).click();
should be
WebElement menuElement = driver.findElement(By.linkText("CARS FOR SALE"));
I am new to selenium. I trying to check whether button is enable or not through isEnabled(). But when I am running this program it generating a error as "Unable to locate element" of button.
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class test
{
static WebDriver driver;
public static void main(String[] args)
{
System.setProperty("webdriver.chrome.driver", "D:\\rakesh\\software\\selenium browser\\New folder\\chromedriver.exe");
driver=new ChromeDriver();
driver.get("https://app.crossover.com/");
driver.manage().window().maximize();
JavascriptExecutor js= (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,5500)", "");
driver.findElement(By.linkText("Available Jobs")).click();
Boolean search_btn_ele = driver.findElement(By.xpath(".//*[#id='available-jobs']/div[2]/form/div/div[3]/button")).isEnabled();
if(search_btn_ele.FALSE)
{
System.out.println("Button is disable before giving search keys");
}
else
{
System.out.println("Button is enable before giving search keys");
}
WebElement search_txtfield_ele= driver.findElement(By.xpath(".//*[#id='available-jobs']/div[2]/form/div/div[1]/div/input"));
search_txtfield_ele.sendKeys("Chief");
}
}
Use WebDriverWait to wait for the element to be present:
new WebDriverWait(driver, TimeSpan.FromSeconds(45)).Until(ExpectedConditions.ElementIsVisible((By.Id("ctl00_ContentPlaceHolder1_drp85"))));
I'm trying to automate www.snapdeal.com using Selenium Webdriver. I'm not able to click a web element inside an iframe as I get Element not visible exception.
Below is the code snippet
package com.snapdeal.framework.rough;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class Lab {
public static WebDriver browser;
public static WebElement currentElement;
public static Actions actions;
public static void main(String[] args) {
//System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"//src//main//resources//chromedriver.exe");
browser = new FirefoxDriver();
browser.get("http://www.snapdeal.com");
browser.manage().window().maximize();
browser.findElement(By.xpath("//*[#id='pincodeSalienceComponent']/div[2]/i")).click();
actions = new Actions(browser);
actions.moveToElement(browser.findElement(By.xpath("//*[#id='accountHeader']/div[1]"))).perform();
actions.moveToElement(browser.findElement(By.xpath("//*[#id='accountHeader']/div[2]/div[2]/div[1]/p/span[2]"))).click().build().perform();
//By executing a java script
JavascriptExecutor exe = (JavascriptExecutor) browser;
Integer numberOfFrames = Integer.parseInt(exe.executeScript("return window.length").toString());
System.out.println("Number of iframes on the page are " + numberOfFrames);
//By finding all the web elements using iframe tag
List<WebElement> iframeElements = browser.findElements(By.tagName("iframe"));
System.out.println(iframeElements.get(0));
System.out.println("The total number of iframes are " + iframeElements.size());
try{
browser.switchTo().frame(1);
}catch(Exception e){
System.out.println(e.getMessage());
}
try{
browser.findElement(By.xpath("//*[#id='login-register-modal']/div[2]/div[2]/div[2]/div")).click();
}catch(Exception e){
System.out.println(e.getMessage());
}
browser.close();
}
}
Could you please guide me on how to get this resolved?
You need to switch to iframe:
// click Mobile number and email button first an then
driver.switchTo().frame("loginIframe");
// after registration is done switch back to top frame:
driver.switchTo().defaultContent();
Here is my code it return null value but is runs well in browser console
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class google {
public static void main(String[] args) throws Exception {
WebDriver driver = new FirefoxDriver();
driver.get("https://in.yahoo.com/");
JavascriptExecutor js;
js = (JavascriptExecutor)driver;
String scriptReturningString = "";
String scriptResult = (String)js.executeScript("return document.getElementsByTagName('body')[0].innerText");
System.out.println("Text Inside:"+scriptResult);
driver.quit();
}
}
WebDriver webDriver = new FirefoxDriver();
webDriver.get("https://in.yahoo.com/");
String content = webDriver.findElement(By.tagName("body")).getText();
System.out.println(content);
This code gets page's content (not source code), stores it in variable content and then prints it in console.
If you want to get page's source code you should use webDriver.getPageSource() method.