SendKeys not working.. tried hundreds of times..

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SendKeys not working.. tried hundreds of times..

Akash Aggarwal
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 !!


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/7f646e4e-2e31-46fb-9e02-1bd0b5578098%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

SendKeys not working.. tried hundreds of times..

Shiva Prasad Adirala
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

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6107d185-abd2-45fe-980f-75d077b564a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: SendKeys not working.. tried hundreds of times..

Akash Aggarwal
In reply to this post by Akash Aggarwal
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?
On Thursday, May 31, 2018 at 6:34:08 PM UTC+5:30, Akash Aggarwal wrote:
My requirement is simplest

I want to open all links of <a href="http://www.yahoo.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.yahoo.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGySK_jCh0Acw8AMI9rJ9rOOjJIpw&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.yahoo.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGySK_jCh0Acw8AMI9rJ9rOOjJIpw&#39;;return true;">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 <a href="http://org.openqa.selenium.By" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.openqa.selenium.By\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEfZQPnvt4Ug_Aq50kJ-TWrQ8CZyg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.openqa.selenium.By\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEfZQPnvt4Ug_Aq50kJ-TWrQ8CZyg&#39;;return true;">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 = "<a href="http://google.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://google.com/&#39;;return true;" onclick="this.href=&#39;http://google.com/&#39;;return true;">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 <a href="http://org.openqa.selenium.By" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.openqa.selenium.By\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEfZQPnvt4Ug_Aq50kJ-TWrQ8CZyg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.openqa.selenium.By\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEfZQPnvt4Ug_Aq50kJ-TWrQ8CZyg&#39;;return true;">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("<a href="http://www.google.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com&#39;;return true;" onclick="this.href=&#39;http://www.google.com&#39;;return true;">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 !!


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0b162bc3-cff0-4971-8a69-43b8211695d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.