# Get Value from browser element in XPCE prolog

**URL:** https://swi-prolog.discourse.group/t/get-value-from-browser-element-in-xpce-prolog/2600
**Category:** Help!
**Created:** [July 4, 2020, 7:39pm UTC](https://swi-prolog.discourse.group/t/get-value-from-browser-element-in-xpce-prolog/2600 "2020-07-04T19:39:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Artem](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Artem](https://swi-prolog.discourse.group/u/Artem)
#### Post date: [July 4, 2020, 7:39pm UTC](https://swi-prolog.discourse.group/t/get-value-from-browser-element-in-xpce-prolog/2600/1 "2020-07-04T19:39:28Z")

</div>

Dear Community,

I have the following problem:

1. I have two browser windows, in one browser window I want to append elements from the drop-down menu by clicking the button “Add”. With this task I have no difficulties.
2. After getting several elements I would like to be able to choose one of the elements in the browser window and by clicking another button “Select” get several predefined options, depending on the previous choice, in the second browser window. This is what created troubles for me. From what I’ve found there are some operators, such as: “get”, “dict” and "dict\_item. However, as I am new to XPCE and I haven’t found clear examples and I am asking for the help from community. The code is as follows:

```prolog
my_form :-

new(D, dialog('Main window', size(800, 800))),
    new(H1, dialog_group(' ')),
  
    send(D, append, H1),
	
	new(ServType, menu(service, cycle)),
    send_list(ServType, append, [abcd, efgh, ijkl, mnop]),
	send(H1, append, ServType),
	
	new(Brow, browser),
	send(H1, append, Brow),
    new(Lb, list_browser),
	send(H1, append, Lb, right),

    send(H1, append, 
         button(add, 
                message(@prolog, add_element, ServType?selection, Lb))),
				
	send(H1, append,
		button(select,
			message(@prolog, add_subelement, ServType?selection, Brow))),	
	
	send(D, open).
    

    add_element(ServType, Lb) :-
        send(Lb, append, ServType).
    	
    add_subelement(ServType, Brow) :-
    	%get(Lb, )
    	ServType == abcd,
    	send_list(Brow, append, [wwww, zzzz, yyyy]);
    	ServType == efgh,
    	send_list(Brow, append, [vvvv, qqqq, uuuu]).
    	
    
    start :- my_form.

```

The core problem is in this part:

```prolog
  add_subelement(ServType, Brow) :-
        	%get(Lb, )
        	ServType == abcd,
        	send_list(Brow, append, [wwww, zzzz, yyyy]);
        	ServType == efgh,
        	send_list(Brow, append, [vvvv, qqqq, uuuu]).

```

Instead of “ServType” I would like to pass the “Lb”, extract the value, check if it corresponds to the set condition and then append some values using “send\_list” to the “Brow” browser element.

Thank you for your help!

N.B. I also published this issue on stackoverflow, link: [https://stackoverflow.com/questions/62721181/get-value-from-browser-element-in-xpce-prolog](https://stackoverflow.com/questions/62721181/get-value-from-browser-element-in-xpce-prolog)

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [July 5, 2020, 8:04am UTC](https://swi-prolog.discourse.group/t/get-value-from-browser-element-in-xpce-prolog/2600/2 "2020-07-05T08:04:14Z")

</div>

What is the problem? Just pass `Lb` using the message you add to the `select` button? I do not recall a limit to the number of arguments you can pass, but if there is it is at least 10.

---

<div class="post-metadata">

### Author: ![Artem](https://avatars.discourse-cdn.com/v4/letter/a/f0a364/32.png) [@Artem](https://swi-prolog.discourse.group/u/Artem)
#### Post date: [July 5, 2020, 1:06pm UTC](https://swi-prolog.discourse.group/t/get-value-from-browser-element-in-xpce-prolog/2600/3 "2020-07-05T13:06:14Z")

</div>

Thank you very much for your reply! I apologize, I was not clear enough. If I got you right, you propose something like:

```prolog
send(H1, append,
    		button(select,
 			message(@prolog, add_subelement, ServType?selection, Lb, Brow))),
....
add_subelement(ServType, Lb, Brow) :-
....

```

But the problem is, how can I extract the value inside the “Brow”, to pass it further. For instance, I have chosen some value in “Lb”, accordingly display the results in the second browser window, like choose “a”, if “a” then “b”, “c”, “d” and then select “b” or “c” or “d” to pass it further. The question is how can I capture the value inside the second browser window, so that I have the full relation chain (“a” -\> “b” or “c” or “d”)? Or another example, in first window I select the car brand, like “Renault” in the second window I get some models of “Renault” like “Megan”, “Clio”, etc, then I select, for instance, “Megan”, so I should get kind of related items or “inherited”, so that “Megan” is always “Renault”. Something like (I know it is wrong):

```prolog
send(H1, append,
    		button(select,
 			message(@prolog, add_subelement, Lb, Brow))),
....
add_subelement(Lb, Brow) :-
Lb.Value == renault,
send_list(Brow, append, [clio, megan]);

```

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [July 6, 2020, 6:47am UTC](https://swi-prolog.discourse.group/t/get-value-from-browser-element-in-xpce-prolog/2600/4 "2020-07-06T06:47:30Z")

</div>

Browser and list\_browser have a get method `selection`. That returns a chain of, or a single `dict_item` object. You can ask that for the key or label.
