SPONSORS:






User Tag List

Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    Apprentice
    Join Date
    Apr 2009
    Location
    Dallas, TX
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Accessing value of input field with no value attribute

    Hello,

    It seems that if you have an input field on a web page and it does not include a value attribute that Selenium cannot read the value of the field. Has anyone else run into this and do you know of a workaround?

    Thanks!
    "All computers wait at the same speed"
    http://capcalblog.blogspot.com

  2. #2
    Member
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    50
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    You can still use .getAttribute("value") to retrieve the text value of the input field. Try this for example:

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.htmlunit.HtmlUnitDriver;

    public class TestField {

    public static void main (String args[]) {

    WebDriver driver = new HtmlUnitDriver();

    driver.get("http://parabank.parasoft.com");
    System.out.println("Input field text value before typing text: " + driver.findElement(By.name("username")).getAttribu te("value"));
    driver.findElement(By.name("username")).sendKeys(" test");
    System.out.println("Input field text value after typing text: " + driver.findElement(By.name("username")).getAttribu te("value"));
    driver.quit();
    }
    }

    The text field used here doesn't have a value attribute (check for yourself), but the above script still works.

  3. #3
    Apprentice
    Join Date
    Apr 2009
    Location
    Dallas, TX
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Thank you so much, I will try this and report back!
    "All computers wait at the same speed"
    http://capcalblog.blogspot.com

  4. #4
    Apprentice
    Join Date
    Apr 2009
    Location
    Dallas, TX
    Posts
    39
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0
    Yes, that worked! Thank you.
    "All computers wait at the same speed"
    http://capcalblog.blogspot.com

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 11.54%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 06:58 PM.

Copyright BetaSoft Inc.