SendKeys not working.. tried hundreds of times..

40 views
Skip to first unread message

Akash Aggarwal

unread,
May 31, 2018, 9:04:08 AM5/31/18
to Selenium Users
My requirement is simplest

I want to open all links of http://www.yahoo.com on a new tabs. I want to do this by clicking on all elements

Below are config 
Macbook Sierra - 10.13.3 (17D47)
Selenium 3.12
Browser - Firefox 3.12

I found that i am not able to use sendKeys, keysDown etc..  Below is the code


package akash.CompleteSelenium.Practice.akash.CompleteSelenium.Practice;


import org.openqa.selenium.By;

import org.openqa.selenium.Keys;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;


public class NewTab {


@Test

public void checkMe() throws Exception {

// TODO Auto-generated method stub


System.setProperty("webdriver.gecko.driver""/Users/akashaggarwal/Documents/" + "geckodriver");


WebDriver driver = new FirefoxDriver();

String baseUrl = "http://google.com/";

driver.get(baseUrl);

driver.findElement(By.cssSelector("body")).sendKeys(Keys.COMMAND + "t");


System.out.println("hello");


}

}



It do not open new tab




If I talk about my bigger problem

package akash.CompleteSelenium.Practice.akash.CompleteSelenium.Practice;


import java.awt.Toolkit;

import java.util.List;


import org.openqa.selenium.By;

import org.openqa.selenium.Keys;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.interactions.Actions;

import org.testng.annotations.Test;


public class PracticeActions {


@Test

public void testMeNow() throws Exception {

// TODO Auto-generated method stub

System.setProperty("webdriver.gecko.driver""/Users/akashaggarwal/Documents/geckodriver");

Toolkit.getDefaultToolkit().beep();


WebDriver driver = new FirefoxDriver();

driver.get("http://www.google.com");

Thread.sleep(10000);

List <WebElement> elements = driver.findElements(By.className("anything"));

System.out.println("***************Size is "+elements.size());

WebElement e=elements.get(0);

Actions newwin = new Actions(driver);

newwin.keyDown(Keys.COMMAND).click(e).keyUp(Keys.COMMAND).build().perform();


}

}



Pls help me!! I am trying since morning !!


Shiva Prasad Adirala

unread,
May 31, 2018, 9:25:01 AM5/31/18
to Selenium Users
Why don't you try robot keyboard action. Something like

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL );
robot.keyPress(KeyEvent.VK_T );
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_T );
Thread.sleep(500);

**Not recommend approach it's a work around

Akash Aggarwal

unread,
May 31, 2018, 10:06:27 AM5/31/18
to Selenium Users
Logs show


1527775512640 geckodriver INFO geckodriver 0.20.0

1527775512649 geckodriver INFO Listening on 127.0.0.1:48003

1527775513518 mozrunner::runner INFO Running command: "/Applications/Firefox.app/Contents/MacOS/firefox-bin" "-marionette" "-profile" "/var/folders/l5/830bqv492h75w8mlvhy3xs3m0000gp/T/rust_mozprofile.HukmUrjC4Hoi"

2018-05-31 19:35:15.817 plugin-container[64583:763195] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x8a43, name = 'com.apple.tsm.portname'

See /usr/include/servers/bootstrap_defs.h for the error codes.

1527775516750 Marionette INFO Listening on port 50233

2018-05-31 19:35:16.813 plugin-container[64584:763265] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x8643, name = 'com.apple.tsm.portname'

See /usr/include/servers/bootstrap_defs.h for the error codes.

1527775516859 Marionette WARN TLS certificate errors will be ignored for this session

May 31, 2018 7:35:17 PM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Detected dialect: W3C



Does Marionette creating this issue?
Reply all
Reply to author
Forward
0 new messages