Selene

Latest version: v1.0.2

Safety actively analyzes 640762 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 3 of 16

2.0.0rc2

Driver is guessed by config.driver_options too

Before:

- `config.driver_name` was `'chrome'` by default

Now:

- `config.driver_name` is `None` by default
- and means "desired requested driver name"
- setting `config.driver_options` usually is enough to guess the driver name,
e.g., just by setting `config.driver_options = FirefoxOptions()`
you already tell Selene to build Firefox driver.

config.driver_service

Just in case you want, e.g. to use own driver executable like:

python
from selene import browser
from selenium.webdriver.chrome.service import Service
from selenium import webdriver

browser.config.driver_service = Service('/path/to/my/chromedriver')
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
browser.config.driver_options = chrome_options


command.select_all to simulate ctrl+a or cmd+a on mac

python
from selene import browser, by, have, command

browser.open('https://www.ecosia.org/')

browser.element(by.name('q')).type('selene').should(have.value('selene'))

browser.element(by.name('q')).perform(command.select_all).type('github yashaka selene')
browser.element(by.name('q')).should(have.value('github yashaka selene'))



Probably might be useful for cases where normal `element.set_value(text)`, while based on `webelement.clear(); webelement.send_keys(text)`, - does not work, in most cases because of some events handled on `clear()`.

command._long_press

More relevant to the mobile case. Might work for web too, but not tested fully for web, not covered with tests. That's why is still marked with `_` as experimental.

2.0.0rc1

Changes

Any custom driver will now be automatically quit at exit

Any driver instance passed to `browser.config.driver` will be automatically quit at exit, unless `browser.config.hold_driver_at_exit = True`, that is `False` by default

Manually set driver can be still automatically rebuilt on next call to browser.open(url)

... if happened to be not alive, e.g. after quit or crash. This was relevant in the past, but not for manually set drivers. Not it works for all cases by default, including manually set driver by `browser.config.driver = my_driver_instance`. To disable this behavior set `browser.config._reset_not_alive_driver_on_get_url = False` (currently this option is still marked as experimental with `_` prefix, it may be renamed till final 2.0 release).

Once automatic rebuild is disabled, you can schedule rebuild on next access to driver by setting `browser.config.driver = ...` (besides ellipsis, setting to `None` also works). This is actually what is done inside `browser.open(url)` if `browser.config._reset_not_alive_driver_on_get_url = True` and driver is not alive.

There is another "rebuild" option in config that is disabled by default: `browser.config.rebuild_not_alive_driver`. It is used to rebuild driver on **any** next access to it, if it is not alive. This is different from `browser.config._reset_not_alive_driver_on_get_url` that resets driver (scheduling to be rebuilt) **only** on next call to `browser.open(url)`. Take into account that enabling this option may leed to slower tests when running on remote drivers, because it will check if driver is alive on any access to it, not only on `browser.open(url)`.


«browser» term is deprecated in a lot of places

2.0.0rc

- set window size inside driver factory
- add safari support (trim space on text in case of safari)
- example of basic auth and auth via cookies (https://github.com/autotests-cloud/example_project/blob/master/src/test/java/cloud/autotests/tests/demowebshop/LoginTests.java)
- can we force order of how `selene.*` is rendered on autocomplete? via `__all__`...
- deprecate `have.js_returned` in favour of `have.script_returned`

2.0.0b14

NEW

command.js.set_style_property(name, value)

python
from selene.support.shared import browser
from selene import command

calling on element
overlay = browser.element('overlay')
overlay.perform(command.js.set_style_property('display', 'none'))

can be also called on collection of elements:
ads = browser.all('[id^=google_ads][id$=container__]')
ads.perform(command.js.set_style_property('display', 'none'))



added conditions: `have.values` and `have.values_containing`

all conditions like `have.texts` & `have.exact_texts` – flatten passed lists of texts

This allows to pass args as lists (even nested) not just as varagrs.

python
from selene.support.shared import browser
from selene import have

"""
GIVEN html page with:
<table>
<tr class="row">
<td class="cell">A1</td><td class="cell">A2</td>
</tr>
<tr class="row">
<td class="cell">B1</td><td class="cell">B2</td>
</tr>
</table>
"""

browser.all('.cell').should(
have.exact_texts('A1', 'A2', 'B1', 'B2')
)

browser.all('.cell').should(
have.exact_texts(['A1', 'A2', 'B1', 'B2'])
)

browser.all('.cell').should(
have.exact_texts(('A1', 'A2', 'B1', 'B2'))
)

browser.all('.cell').should(
have.exact_texts(
('A1', 'A2'),
('B1', 'B2'),
)
)


removed trimming text on conditions like have.exact_text, have.texts, etc.

because all string normalization is already done by Selenium Webdriver.

but added query.text_content to give access to raw element text without space normalization

2.0.0b13

NEW

have.text, have.exact_text, have.texts and have.exact_texts strip/trim text when matching

config.window_width and config.window_height can be set separately

Now, you can set only one axis dimension for the browser, and it will change it on `browser.open`. Before it would change browser window size only if both width and height were set;)

access to self.locate() as `element` or `self` from the script passed to element.execute_script(script_on_self, *arguments)

Examples:

python
from selene.support.shared import browser

browser.element('[id^=google_ads]').execute_script('element.remove()')
OR
browser.element('[id^=google_ads]').execute_script('self.remove()')
'''
are shortcuts to
browser.execute_script('arguments[0].remove()', browser.element('[id^=google_ads]')())
'''

browser.element('input').execute_script('element.value=arguments[0]', 'new value')
OR
browser.element('input').execute_script('self.value=arguments[0]', 'new value')
'''
are shortcuts to
browser.execute_script('arguments[0].value=arguments[1]', browser.element('input').locate(), 'new value')
'''


`collection.second` shortcut to `collection[1]`

`element.locate() -> WebElement`, `collection.locate() -> List[WebElement]` [284](https://github.com/yashaka/selene/issues/284)

... as more human-readable aliases to element() and collection() correspondingly

`entity.__raw__`

It's a «dangled» property and so consider it an experimental/private feature.
For element and collection – it's same as `.locate()`.
For `browser` it's same as `.driver` ;)

Read more on it at this [comment to 284](https://github.com/yashaka/selene/issues/284#issuecomment-1265619606)

... as aliases to element(), collection() correspondingly

NEW: DEPRECATED:

element._execute_script(script_on_self, *args)

... in favor of .execute_script(script_on_self, *arguments) that uses access to arguments (NOT args!) in the script.

collection.filtered_by(condition) in favor of collection.by(condition)

browser.close_current_tab()

Deprecated because the «tab» term is not relevant for mobile context.
Use a `browser.close()` or `browser.driver.close()` instead.

The deprecation mark was removed from the `browser.close()` correspondingly.

`browser.clear_session_storage()` and `browser.clear_local_storage()`

Deprecated because of js nature and not-relevance for mobile context;
Use `browser.perform(command.js.clear_session_storage)` and `browser.perform(command.js.clear_local_storage)` instead

NEW: BREAKING CHANGES

arguments inside script passed to element.execute_script(script_on_self, *arguments) starts from 0

python
from selene.support.shared import browser

before this version ...
browser.element('input').execute_script('arguments[0].value=arguments[1]', 'new value')
NOW:
browser.element('input').execute_script('element.value=arguments[0]', 'new value')


removed earlier deprecated

- `browser.elements(selector)` in favor of `browser.all(selector)`
- `browser.ss(selector)` in favor of `browser.all(selector)`
- `browser.s(selector)` in favor of `browser.element(selector)`
- `element.get_actual_webelement()` in favor of `element.locate()`
- `collection.get_actual_webelements()` in favor of `collection.locate()`

renamed collection.filtered_by_their(selector, condition) to collection.by_their(selector, condition)

removed collection.should_each ... [277](https://github.com/yashaka/selene/issues/277)

- ... and ability to pass element_condition to `collection.should(HERE)`
- Use instead: `collection.should(element_condition.each)`
- like in `browser.all('.selene-user').should(hava.css_class('cool').each)`

2.0.0b12

NEW: collection.should(condition.each) [277](https://github.com/yashaka/selene/issues/277)

The older style is totally **deprecated** now:
- Instead of:
- `collection.should(element_condition)` and `collection.should_each(element_condition)`
- Use:
- `collection.should(element_condition.each)`
- see more examples at [tests/integration/condition_each_test.py](https://github.com/yashaka/selene/tree/master/tests/integration/condition_each_test.py)

NEW: BREAKING CHANGE: removed SeleneElement, SeleneCollection, SeleneDriver

use instead:

python
import selene

element: selene.Element = ...
collection: selene.Collection = ...
browser: selene.Browser = ...


or:

python
from selene import Element, Collection, Browser

element: Element = ...
collection: Collection = ...
browser: Browser = ...

Page 3 of 16

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.