Below is the code
WebDriver dr= new ChromeDriver();
dr.get("http://obsessory.com/");
dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[1]/a")).click();
dr.findElement(By.id("email")).sendKeys("username#gmail.com");
dr.findElement(By.name("LoginForm[password]")).sendKeys("password");
dr.findElement(By.xpath(".//[#id='signIn']/div[2]/div[3]/div[3]/input")).click();
Actions action = new Actions(dr);
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a/span"));
action.moveToElement(we).moveToElement(dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a"))).click().build().perform();
I wanted to click on 'my accounts' or any of those other links. Kindle tell me how to do that
#kavya
Please try this code. I think you are not able to type password in password textbox.
For password:
dr.findElement(By.xpath("(//input[#id='email'])[2]")).sendKeys("obsessory");
For Menu:
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a"));
WebElement ve = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a"));
Actions act = new Actions(dr);
act.moveToElement(we).click(ve).perform();
Hope this will work
Try with
Actions action= new Actions(dr);
WebElement we = dr.findElement(By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/a/span"));
action.moveToElement(we).perform();
By locator = By.xpath("html/body/header/div[2]/div[1]/ul/li[4]/ul/li[1]/a");
dr.click(locator);
Related
I have wicket aplication, and I want to set one select value. Problem is that chrome driver returns error with RESPONSE FindElement ERROR
no such element: Unable to locate element: {"method":"css selector","selector":"#id104"}
(Session info: chrome=94.0.4606.81)
Here is my selenium java code:
System.setProperty("webdriver.chrome.driver", pathToDriver);
System.setProperty("webdriver.chrome.logfile", "C:\\app\\chromedriver.log");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("C:\\app\\GoogleChromePortable64\\App\\Chrome-bin\\chrome.exe");
WebDriver driver=new ChromeDriver(chromeOptions);
driver.navigate().to(url);
System.out.println(driver.getCurrentUrl());
WebElement userTextField = driver.findElement(By.id("username"));
userTextField.sendKeys(username);
WebElement passwordTextField = driver.findElement(By.id("password"));
passwordTextField.sendKeys(password);
WebElement okButton =driver. findElement(By.id("OKButton"));
okButton.click();
WebElement crdbTab =driver. findElement(By.linkText("CRDB"));
crdbTab.click();
(new WebDriverWait(driver, 5)).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("iframe_app4"));
WebElement uploadTab = driver.findElement(By.linkText("Upload"));
uploadTab.click();
System.out.println(driver.getCurrentUrl());
WebElement fileUploadButton = driver.findElement(By.id("id5f"));
fileUploadButton.sendKeys(filePath);
driver.findElement(By.id("idb")).click();
driver.findElement(By.className("main")).click();
Select headerDataSelect = new Select(driver.findElement(By.id("id104")));
headerDataSelect.selectByIndex(0);
Code fails on
Select headerDataSelect = new Select(driver.findElement(By.id("id104")));
Can someone give a point on how to solve this issue?
Thanks for help
Try adding a wait there to make elements loaded before accessing them.
Instead of
Select headerDataSelect = new Select(driver.findElement(By.id("id110")));
Try
wait = new WebDriverWait(driver, 30);
Select headerDataSelect = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id110"))));
Also make sure the id value id110 is unique and not dynamic here.
WebDriver driver = new ChromeDriver();
driver.get('https://www.nvidia.com/en-gb/shop/geforce/?page=1&limit=9&locale=en-gb');
WebElement notify = driver.findElement(By.id('cookiePolicy-btn-close'));
notify.click();
WebElement buyButton = driver.findElement(By.className('featured-buy-link link-btn'));
buyButton.click();
I'm trying to click in some JQUERY elements from a very known website to practice Selenium (http://the-internet.herokuapp.com/jqueryui/menu).
I figured out how to navigate into the menu (not sure if my code is a good solution), however am not being able to click in each last submenu option (PDF, CSV, Excel)
I'm trying something like below:
Actions builder = new Actions(driver);
Action mouseOverMenu;
mouseOverMenu = builder.moveToElement(driver.findElement(By.id("ui-id-2"))).build();
mouseOverMenu.perform(); //accessing Enabled menu option
mouseOverMenu = builder.moveToElement(driver.findElement(By.id("ui-id-4"))).build();
mouseOverMenu.perform(); //accessing Downloads submenu option
String jQuerySelector = "$('a#ui-id-6.ui-corner-all')";
WebElement webElement = (WebElement) ((JavascriptExecutor) driver).executeScript("return $(" + jQuerySelector+ ").get(0);");
//click() also did not work
WebElement webElement = (WebElement) ((JavascriptExecutor) driver).executeScript("return $(" + jQuerySelector+ ").click();");
Your JavaScript function of click is wrong.
Use below javascript syntax
executor.executeScript("arguments[0].click();", WebElement);
Below code works for me:
Actions builder = new Actions(driver);
Action mouseOverMenu;
mouseOverMenu = builder.moveToElement(driver.findElement(By.id("ui-id-2"))).build();
mouseOverMenu.perform(); //accessing Enabled menu option
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ui-id-4")));
wait.until(ExpectedConditions.elementToBeClickable(By.id("ui-id-4")));
mouseOverMenu = builder.moveToElement(driver.findElement(By.id("ui-id-4"))).build();
mouseOverMenu.perform(); //accessing Downloads submenu option
WebElement webElement2= driver.findElement(By.cssSelector("a#ui-id-6.ui-corner-all")); // #ui-id-6 is for pdf, #ui-id-7 csv so on
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", webElement2);
I'm using the following to navigate a menu in Selenium. It works perfectly in Chrome, however in IE, it ends up clicking the menu below my target and the submenu item becomes completely inaccessible.
// Actions not supported by FireFox's Marionette Driver, use chrome or ie.
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.id("m7f8f3e49_ns_menu_INVENTOR_MODULE_a_tnode"));
System.out.println("Found the inventory text");
actions.moveToElement(menuHoverLink);
WebElement subLink = driver.findElement(By.id("m7f8f3e49_ns_menu_INVENTOR_MODULE_sub_changeapp_INVENTOR_a"));
actions.moveToElement(subLink);
actions.click();
actions.perform();
And here is where the drive is initialized
System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer64.exe");
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
I would like to be able to click on the proper menu item to continue with my testing.
I managed to get a working solution by moving the cursor over from the offset. Not sure how well this will work across screens.
Actions actions = new Actions(driver);
WebElement menuHoverLink = driver.findElement(By.linkText(arg1));
//<span id="m7f8f3e49_ns_menu_INVENTOR_MODULE_a_tnode">Inventory</span>
System.out.println("Found the inventory text");
actions.moveToElement(menuHoverLink);
actions.moveByOffset(100, 10);
Thread.sleep(1000);
//actions.moveByOffset(45, 0);
WebElement subLink = driver.findElement(By.
id("m7f8f3e49_ns_menu_INVENTOR_MODULE_sub_changeapp_SRVITEM_a_tnode"));
actions.moveToElement(subLink, 100, 12)
.click().perform();
The task is press button "More" in https://play.google.com/store/apps/category/FINANCE/collection/topselling_paid
This is screenshot
http://c2n.me/i9LC1O
My code is:
String url = "https://play.google.com/store/apps/category/FINANCE/collection/topselling_paid";
WebDriver driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(100000, TimeUnit.SECONDS);
driver.get(url);
//Collects ONLY first 60 link. `enter code here`But I need more....
ArrayList<WebElement> linksToApp = (ArrayList<WebElement>) driver
.findElements((By.className("title")));
ArrayList<String> urlToApp = new ArrayList<String>();
Please, help me.
You need to do something like
driver.findElement(By.id("id-of-show_more-button")).click();
You can find the element id byt right clicking on the element, click on inspect element and then checking for the id attribute in the HTML