0

I am able to read but not set. Why?

.FindElementByCss(".multiselect__single.per-page-text").text

returns 25

.FindElementByCss(".multiselect__single.per-page-text").text = 50

Gives:

Assignment to constant not permitted

How to resolve this?

I am getting an element not interactive error on the following statement:

.FindElementByCss(".multiselect__single.per-page-text").SendKeys (50)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • WebDriver command send GET request to retrieve text attribute value - that's the reason why you cannot set its value. Without the page source/link to the app there is no way to say more how to help you. – Piotr M. Jan 31 '21 at 16:54
  • If it's not an input tag you can't send keys. – Arundeep Chohan Jan 31 '21 at 17:18

2 Answers2

0

You should understand how selenium works

This is the architecture of selenium communication.

enter image description here

  1. Each browser have its on driver that can communicate to the browser and make it do some actions.
  2. The driver exposes the methods that it supports like clicking button , sending values extra through an API
  3. Selenium libraries in different languages calls this API and API calls the corresponding method
  4. Once the method is called chromedriver talks to browser to do this particular actions.

So .FindElementByCss(".multiselect__single.per-page-text").text

Calls the api to findthe element and give the innerText , driver calls particular method which contacts the browser to get the information and once it gets it back to the client.

IN the chromedriver API .text is a constant or final identifier which cannot be changed from client so it cannot be modified from client.

But nothing stops you from modifying it by executing javascript on the browser directly.

driver.executeScript("arguments[0].text=arguments[1]",driver.FindElementByCss(".multiselect__single.per-page-text"),50);
PDHide
  • 18,113
  • 2
  • 31
  • 46
0

This error message...

Assignment to constant not permitted

...implies that you tried to assign a new value to a variable declared with Const, or to a type library constant. If you need to assign a new value, declare an ordinary variable of the type desired and assign your value to that variable.


As you are able to retrieve the text 25 possibly it's a readonly field and you won't be able to set any other value even manually. However, the relevant HTML would have helped us to conclude in a better way.

Conclusion / Solution

Incase it's a readonly field you won't be able to set any other text of your choice. Else, in-case the value within the field is editable, to set a value avoiding element not interactive you need to use SendKeys you can use either of the following Locator Strategies:

  • Using FindElementByCss:

    newHour = Hour(Now()) 
    newMinute = Minute(Now()) 
    newSecond = Second(Now()) + 10 
    waitTime = TimeSerial(newHour, newMinute, newSecond) 
    driver.Wait waitTime
    driver.FindElementByCss(".multiselect__single.per-page-text").SendKeys "50"
    
  • Using FindElementByXPath:

    newHour = Hour(Now()) 
    newMinute = Minute(Now()) 
    newSecond = Second(Now()) + 10 
    waitTime = TimeSerial(newHour, newMinute, newSecond) 
    driver.Wait waitTime
    driver.FindElementByXPath("//*[@class='multiselect__single per-page-text'][contains(@name, 'ContentPlaceHolder1')]").SendKeys "50"
    

Reference

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352