Skip to content

Commit fd9d8d8

Browse files
committed
[py]: Simplify some pointer_input code
1 parent a7ddeca commit fd9d8d8

2 files changed

Lines changed: 23 additions & 18 deletions

File tree

py/selenium/webdriver/common/actions/pointer_input.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
from .input_device import InputDevice
18-
from .interaction import POINTER, POINTER_KINDS
17+
import typing
1918

2019
from selenium.common.exceptions import InvalidArgumentException
2120
from selenium.webdriver.remote.webelement import WebElement
21+
from .input_device import InputDevice
22+
from .interaction import POINTER, POINTER_KINDS
2223

2324

2425
class PointerInput(InputDevice):
25-
2626
DEFAULT_MOVE_DURATION = 250
2727

2828
def __init__(self, kind, name):
@@ -34,20 +34,25 @@ def __init__(self, kind, name):
3434
self.name = name
3535

3636
def create_pointer_move(self, duration=DEFAULT_MOVE_DURATION, x=0, y=0, origin=None, **kwargs):
37-
action = dict(type="pointerMove", duration=duration)
38-
action["x"] = x
39-
action["y"] = y
40-
action.update(**kwargs)
37+
action = {
38+
"type": "pointerMove",
39+
"duration": duration,
40+
"x": x,
41+
"y": y,
42+
**kwargs
43+
}
4144
if isinstance(origin, WebElement):
4245
action["origin"] = {"element-6066-11e4-a52e-4f735466cecf": origin.id}
43-
elif origin:
46+
elif origin is not None:
4447
action["origin"] = origin
45-
4648
self.add_action(self._convert_keys(action))
4749

4850
def create_pointer_down(self, **kwargs):
49-
data = dict(type="pointerDown", duration=0)
50-
data.update(**kwargs)
51+
data = {
52+
"type": "pointerDown",
53+
"duration": 0,
54+
**kwargs
55+
}
5156
self.add_action(self._convert_keys(data))
5257

5358
def create_pointer_up(self, button):
@@ -65,15 +70,15 @@ def encode(self):
6570
"id": self.name,
6671
"actions": self.actions}
6772

68-
def _convert_keys(self, actions):
73+
def _convert_keys(self, actions: typing.Dict[str, typing.Any]):
6974
out = {}
70-
for k in actions.keys():
71-
if actions[k] is None:
75+
for k, v in actions.items():
76+
if v is None:
7277
continue
73-
if k == "x" or k == "y":
74-
out[k] = int(actions[k])
78+
if k in ("x", "y"):
79+
out[k] = int(v)
7580
continue
7681
splits = k.split('_')
7782
new_key = splits[0] + ''.join(v.title() for v in splits[1:])
78-
out[new_key] = actions[k]
83+
out[new_key] = v
7984
return out

py/selenium/webdriver/common/proxy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def socks_version(self, value) -> None:
320320
self.socksVersion = value
321321

322322
def _verify_proxy_type_compatibility(self, compatible_proxy):
323-
if self.proxyType != ProxyType.UNSPECIFIED and self.proxyType != compatible_proxy:
323+
if self.proxyType not in (ProxyType.UNSPECIFIED, compatible_proxy):
324324
raise Exception(f"Specified proxy type ({compatible_proxy}) not compatible with current setting ({self.proxyType})")
325325

326326
def add_to_capabilities(self, capabilities):

0 commit comments

Comments
 (0)