Re: keyDown(keys.CONTROL) not working at all

663 views
Skip to first unread message
Message has been deleted

Jim Evans

unread,
Feb 27, 2013, 6:29:09 AM2/27/13
to seleniu...@googlegroups.com
Vague, snide comments about how you think an implementation is broken won't get you much sympathy, I'm afraid. If you have issues with how the IE driver has been implemented, feel free to bring them up. That's the only way the driver will get better, is by knowing what isn't working correctly.

HPK

unread,
Feb 27, 2013, 9:38:57 AM2/27/13
to seleniu...@googlegroups.com
It will be more easy to do the following instead of using KeyDown

  • Read the value of the text box using something like driver.findElement(By.id("id_story")).getAttribute("value")
  • Process the data as you wish
  • Clear the text box using  driver.findElement(By.id("id_story")).clear();
  • Type your new value in using sendKeys()
HPK


On Tuesday, February 26, 2013 5:44:53 AM UTC, Michael Reid wrote:
Eclipse IDE
Selenium Stand-alone server 2.30.0
FireFox ESR ver. 17.0.3
WebDriver ver. 2.28.0
Frustration ver. 10
Time Invested Considerable!

code is as follows.

Actions action = new Actions(driver); 
WebElement tagElement = driver.findElement(By.id("id_story"));
action.sendKeys(tagElement).click();  // this was an attempt to ensure I was in the box prior to the control event.
action.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).keyUp(Keys.CONTROL).perform(); // I have tried with and without the keyUP per a stackoverflow suggestion

The only thing that happens is the correct textbox is selected, and the cursor will jump to the home position of the last line.

I have tried numerous combinations of the above. and the effects have varied, but none resulted in my cursor being at the top leftmost position in the textbox.
I have also attempted to use moveToElement( tagElement, 0, 0).click() with no success either. though I'm not sure if my implementation was correct. I admit I am extremely raw at this.  This is my first real foray into java. 

I don't care how I accomplish it, I just really need to select my textbox with the id of id_story.  get the cursor to the first line, 0 position, so I can then delete a few characters(which varies in amount).

if I can cut / trim /paste that would be great!

sendkeys isn't an option it executes to slowly for the amount of text that can be involved. I have used that method for a smaller chunk of text, where I read in the value of id_tease into a VAR, trim it, then sendkey it back in, because it is only a sentence or two its not eating up to much time, however the main body of text can be up to a few thousand words long.  This would be a tad bit tedious to wait through, when I have 10-30 pages to process in some cases, and potentially up to 100 pages.

If someone can confirm that it would work in CHROME or IE 9, I will gladly convert over this is not for regression testing on multi-platform, this is for automation.  So like I said, any solution other than sendkeys would be absolutely wonderful!







Michael Reid

unread,
Feb 27, 2013, 10:12:22 AM2/27/13
to seleniu...@googlegroups.com
HPK,

Thank you for your reply, I do appreciate the insight.  However, in some cases it could easily be 1000+ Keystrokes, I have actually used the exact technique you mentioned in the previous textbox,  since it will never be more than a sentence or two.
Manually I can process the page in approximately 12 seconds.  
However the save time of the edited page, and the load time of the next page is approximately 30-45 seconds due to server load.
So if I can automate the processing of the 30-80 pages a night I can move onto other things while this processes in the background.
But I do still need it to be done in a reasonable amount of time, so I have been attempting this method because I just need to trim the dateline from the beginning of the story.

--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/dhUYlHQlQ48/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/ber_Duases4J.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jim Evans

unread,
Feb 27, 2013, 1:33:20 PM2/27/13
to seleniu...@googlegroups.com
"Building the driver in @Test, not @Before" is not unique to the IE driver. I would imagine that somewhere within your class, outside of any methods, you have a variable named "driver". Your class probably looked something like this:

//****************************** Start code sample ********************************

public class MyClass {
  WebDriver driver;

  @Before
  public void setUp() {
    File file = new File("C:/Selenium/iedriverserver.exe");
    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());

    // *************************************************
    // HERE IS WHERE YOUR PROBLEM WAS!!!
    // Hold onto that thought, and I'll describe what went wrong below.
    // *************************************************
    WebDriver driver = new InternetExplorerDriver();

    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testLoop() {
    driver.get("http://the/url/you/want/to/go/to");
  }
}

//****************************** End code sample ********************************

By using the type "WebDriver" in the line I marked in the sample, you declared a local variable named "driver" in your setUp() method. This local variable could *only* be seen within that setUp() method, and it will hide the one declared at the class level. The testLoop() method can access the class-level variable named "driver", but it has no way at all to see the local variable declared in the setUp() method. So you set this *local* driver to the brand-new instance of the IE driver that you've created, not the class-level driver, which remains null. Then, when the testLoop() method dutifully tries to use the class-level "driver" variable, it's never been set to anything other than null, so you naturally get a NullPointerException.

How do you fix it? Just remove the word "WebDriver" from the setUp() method. That changes the line from a declaration of a new variable named "driver" to accessing the already-declared class-level variable named "driver".

And this is another example of why *complete* code is often required when asking for assistance, instead of just small snippets.

--Jim

On Wednesday, February 27, 2013 9:42:41 AM UTC-5, Michael Reid wrote:
For those receiving java.lang.NullPointerException when implementing IEDriverServer this may help you.

I had put two days into attempting to get that one functionality to work. It wasn't intended as snide, it was intended as exhausted.
I worked on it further for hours, with no input from any of the resources I tried to gain insight from.  So I posted a quick reply to my own post so that others that may stumble on it over the years, would at least know I worked around the issue.

Went on to attempt to implement the IE Driver in another class.  Used examples from StackOverflow, because I can't read the syntax that is used to describe java functions. It makes my eyes cross. anyhow I'm learning one week at a time.  I have been working for six weeks to create one automation script that performs a number of complicated steps on a web page to take news stories live for the local paper.  Every time I turn around I find myself spending 3 to 4 hours finding workarounds for things that almost work, or used to work but now don't. 

So lessons learned about the IE Driver is that you need to build the driver in  @TEST not the @ Before.

In the green highlight you will see that I attempt to setup the driver in @Before this will result in the following, when it hits the last line highlighted in dark green. Could it be me most likely, however, I'm a noob at JAVA and Selenium
java.lang.NullPointerException
at com.example.tests.Categories_ie9.testLoop(Categories_ie9.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

  @Before
  public void setUp() throws Exception {
  File file = new File("C:/Selenium/iedriverserver.exe");
     System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
     WebDriver driver = new InternetExplorerDriver();
    
     
         driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    
}   
    
  

  @Test
 
  public void testLoop() throws Exception {
  
    try {
     
       
     // Setup Story Loop Numbers
     int x = Integer.parseInt(JOptionPane.showInputDialog("Starting Story Number"));
     int y = Integer.parseInt(JOptionPane.showInputDialog("Ending Story Number")) ;
     while (y >= x) {
            System.out.println("Count is: " + x);
           
  final String sUrl = "http://www.nwaonline.com/admin/news/story/" + x ;          
                           
   // driver.get("http://www.nwaonline.com/admin/news/story/" + x + "/");
            driver.get(sUrl);

When I move the code block highlighted in blue into @Test the code functions.  However the FireFox Driver does not "die" tranversing the code blocks.  So this resolves the Null Exception Error.

  @Before
  public void setUp() throws Exception {
  xxxxxxxxxxx
xxxxxMoved Code from Here into @TESTxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxx
    
}   
    
  

  @Test
 
  public void testLoop() throws Exception {
  
    try {
     File file = new File("C:/Selenium/iedriverserver.exe");
     System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
     WebDriver driver = new InternetExplorerDriver();
    
     
         driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);        
     // Setup Story Loop Numbers
     int x = Integer.parseInt(JOptionPane.showInputDialog("Starting Story Number"));
     int y = Integer.parseInt(JOptionPane.showInputDialog("Ending Story Number")) ;
     while (y >= x) {
            System.out.println("Count is: " + x);
           
  final String sUrl = "http://www.nwaonline.com/admin/news/story/" + x ;          
                           
   // driver.get("http://www.nwaonline.com/admin/news/story/" + x + "/");
            driver.get(sUrl);


Reply all
Reply to author
Forward
0 new messages