-2

Suppose I have a config.cfg file with the following:

[Info]
keyword: Cool Shirt

How would I pass keyword into a URL, such that

driver.get("http://www.somewebsite.com/checkout?keyword")

achieves the same result as

driver.get("http://www.somewebsite.com/checkout?keyword=Cool+Shirt")?

solo
  • 743
  • 2
  • 6
  • 17
  • You want this whole line "keyword=Cool+Shirt" in url ? – Ankur Singh Dec 24 '17 at 18:59
  • String URL=String.format("http://www.somewebsite.com/checkout?%s",keyword); You can try thi code – Ankur Singh Dec 24 '17 at 19:01
  • @AnkurSingh Effectively, yes. I'd like to automate filling in the keyword field in the given URL; the constraint, however, is that I'd like to do so by using the global variable from the config.cfg file. – solo Dec 24 '17 at 19:03
  • 1
    You can read your keyword value from config file "http://www.opencodez.com/java/read-config-file-in-java.htm" using this way and then pass it into string formater to build string as you want – Ankur Singh Dec 24 '17 at 19:08
  • @AnkurSingh I'm not sure I follow. I tried the first case and got `name 'string' is not defined`. – solo Dec 24 '17 at 19:21
  • @AnkurSingh Nvm, got it to work! Thank you for your help. – solo Dec 24 '17 at 19:29
  • Not related to Python! – Vahid Kharazi Dec 24 '17 at 19:44

1 Answers1

1

You can read your keyword value from config file "opencodez.com/java/read-config-file-in-java.htm"; using this way and then pass it into string formater to build string as you want

String URL=String.format("somewebsite.com/checkout?%s",keyword);
JeffC
  • 22,180
  • 5
  • 32
  • 55
Ankur Singh
  • 1,239
  • 1
  • 8
  • 18