Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[py]: use By class attributes instead of strings #15402

Merged
merged 2 commits into from
Mar 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions py/selenium/webdriver/remote/locator_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from selenium.webdriver.common.by import By


class LocatorConverter:
def convert(self, by, value):
# Default conversion logic
if by == "id":
return "css selector", f'[id="{value}"]'
elif by == "class name":
return "css selector", f".{value}"
elif by == "name":
return "css selector", f'[name="{value}"]'
if by == By.ID:
return By.CSS_SELECTOR, f'[id="{value}"]'
elif by == By.CLASS_NAME:
return By.CSS_SELECTOR, f".{value}"
elif by == By.NAME:
return By.CSS_SELECTOR, f'[name="{value}"]'
return by, value
Loading