sendKeys(Keys.COMMAND+"t"); - SendKEYS IS WORKING FOR TEXT, HOWEVER DO NOT WORK FOR Keys.COMMAND+"t

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

sendKeys(Keys.COMMAND+"t"); - SendKEYS IS WORKING FOR TEXT, HOWEVER DO NOT WORK FOR Keys.COMMAND+"t

Akash Aggarwal

6:34 PM (1 hour ago)
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 60.0.1 (64-bit)


Below is complete 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.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;


public class NewTab {


@Test

public void paytmMall() 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);

//WebElement d =driver.findElement(By.cssSelector("body"));

WebElement d =driver.findElement(By.id("lst-ib"));

d.sendKeys("hi");

d.click();

System.out.println("&&&&&&&&&&&&&&&&&&&&"+d.toString());

d.sendKeys(Keys.COMMAND+"t");


System.out.println("hello");


}

}



LOGS

[RemoteTestNG] detected TestNG version 6.8.0

[TestNG] Running:

  /private/var/folders/l5/830bqv492h75w8mlvhy3xs3m0000gp/T/testng-eclipse--1428727419/testng-customsuite.xml


1527777012788 geckodriver INFO geckodriver 0.20.0

1527777012799 geckodriver INFO Listening on 127.0.0.1:23602

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

2018-05-31 20:00:16.689 plugin-container[65578:774537] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x763f, name = 'com.apple.tsm.portname'

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

2018-05-31 20:00:17.589 plugin-container[65589:774623] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x8a3f, name = 'com.apple.tsm.portname'

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

1527777017622 Marionette INFO Listening on port 57536

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

May 31, 2018 8:00:17 PM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Detected dialect: W3C

&&&&&&&&&&&&&&&&&&&&[[FirefoxDriver: firefox on MAC (d669a556-6d9c-2141-af87-99e99c4e86de)] -> id: lst-ib]

hello

PASSED: paytmMall


===============================================

    Default test

    Tests run: 1, Failures: 0, Skips: 0

===============================================



===============================================

Default suite

Total tests run: 1, Failures: 0, Skips: 0

===============================================


[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms

[TestNG] Time taken by org.testng.reporters.EmailableReporter@3b6eb2ec: 19 ms

[TestNG] Time taken by org.testng.reporters.jq.Main@6bdf28bb: 142 ms

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@129a8472: 42 ms

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@34ce8af7: 4 ms

[TestNG] Time taken by org.testng.reporters.XMLReporter@43a25848: 17 ms

--
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/a3502225-ac88-4eea-9e08-563dbbdafbdf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sendKeys(Keys.COMMAND+"t"); - SendKEYS IS WORKING FOR TEXT, HOWEVER DO NOT WORK FOR Keys.COMMAND+"t

radha janagouda
Basically as per your requirement you should be opening all the links in new tab, but here you are trying to enter hi in some text box,

questions for you-
1) are you trying to enter "hi" in search text box?, if yes then findelements path of that is incorrect.
 i searched for "lst-ib" doesnt looks like anything of this id is present, moreover using id for locating is little risky as these id;s keep changing.

Solution should be -
you need to just find xpath of all links and click on them.

On Thursday, 31 May 2018 20:04:32 UTC+5:30, Akash Aggarwal wrote:

6:34 PM (1 hour ago)
My requirement is simplest

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


Below is complete 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.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;


public class NewTab {


@Test

public void paytmMall() 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);

//WebElement d =driver.findElement(By.cssSelector("body"));

WebElement d =driver.findElement(By.id("lst-ib"));

d.sendKeys("hi");

d.click();

System.out.println("&&&&&&&&&&&&&&&&&&&&"+d.toString());

d.sendKeys(Keys.COMMAND+"t");


System.out.println("hello");


}

}



LOGS

[RemoteTestNG] detected TestNG version 6.8.0

[TestNG] Running:

  /private/var/folders/l5/830bqv492h75w8mlvhy3xs3m0000gp/T/testng-eclipse--1428727419/testng-customsuite.xml


1527777012788 geckodriver INFO geckodriver 0.20.0

1527777012799 geckodriver INFO Listening on <a href="http://127.0.0.1:23602" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2F127.0.0.1%3A23602\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGK_PM_PzW_s0Q5W6slj_a2zLwQsg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2F127.0.0.1%3A23602\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGK_PM_PzW_s0Q5W6slj_a2zLwQsg&#39;;return true;">127.0.0.1:23602

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

2018-05-31 20:00:16.689 plugin-container[65578:774537] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x763f, name = 'com.apple.tsm.portname'

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

2018-05-31 20:00:17.589 plugin-container[65589:774623] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0x8a3f, name = 'com.apple.tsm.portname'

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

1527777017622 Marionette INFO Listening on port 57536

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

May 31, 2018 8:00:17 PM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Detected dialect: W3C

&&&&&&&&&&&&&&&&&&&&[[FirefoxDriver: firefox on MAC (d669a556-6d9c-2141-af87-99e99c4e86de)] -> id: lst-ib]

hello

PASSED: paytmMall


===============================================

    Default test

    Tests run: 1, Failures: 0, Skips: 0

===============================================



===============================================

Default suite

Total tests run: 1, Failures: 0, Skips: 0

===============================================


[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms

[TestNG] Time taken by org.testng.reporters.EmailableReporter@3b6eb2ec: 19 ms

[TestNG] Time taken by org.testng.reporters.jq.Main@6bdf28bb: 142 ms

[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@129a8472: 42 ms

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@34ce8af7: 4 ms

[TestNG] Time taken by org.testng.reporters.XMLReporter@43a25848: 17 ms

--
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/04d4b2f9-717e-48ec-9b86-c318f28f729d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.