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

43 views
Skip to first unread message

Akash Aggarwal

unread,
May 31, 2018, 10:34:32 AM5/31/18
to Selenium Users

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

Auto Generated Inline Image 1

radha janagouda

unread,
Jun 1, 2018, 4:54:33 AM6/1/18
to Selenium Users
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.
Reply all
Reply to author
Forward
0 new messages