<commit_before># Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

import pytest

from selenium.common.exceptions import (
    ElementNotSelectableException,
    InvalidElementStateException,
    NoSuchElementException,
    UnexpectedTagNameException)
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By

disabledSelect = {'name': 'no-select', 'values': ['Foo']}
singleSelectValues1 = {'name': 'selectomatic', 'values': ['One', 'Two', 'Four', 'Still learning how to count, apparently']}
singleSelectValues2 = {'name': 'redirect', 'values': ['One', 'Two']}
singleSelectValuesWithSpaces = {'name': 'select_with_spaces', 'values': ['One', 'Two', 'Four', 'Still learning how to count, apparently']}
multiSelectValues1 = {'name': 'multi', 'values': ['Eggs', 'Ham', 'Sausages', 'Onion gravy']}
multiSelectValues2 = {'name': 'select_empty_multiple', 'values': ['select_1', 'select_2', 'select_3', 'select_4']}


def testSelectByIndexSingle(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        for x in range(len(select['values'])):
            sel.select_by_index(x)
            assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_chrome
@pytest.mark.xfail_firefox
@pytest.mark.xfail_remote
@pytest.mark.xfail_marionette(raises=InvalidElementStateException)
@pytest.mark.xfail_phantomjs
@pytest.mark.xfail_safari
def testSelectDisabledByIndexShouldThrowException(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
    with pytest.raises(ElementNotSelectableException):
        sel.select_by_index(1)


def testSelectByValueSingle(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        for x in range(len(select['values'])):
            sel.select_by_value(select['values'][x].lower())
            assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_chrome
@pytest.mark.xfail_firefox
@pytest.mark.xfail_remote
@pytest.mark.xfail_marionette(raises=InvalidElementStateException)
@pytest.mark.xfail_phantomjs
@pytest.mark.xfail_safari
def testSelectDisabledByValueShouldThrowException(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
    with pytest.raises(ElementNotSelectableException):
        sel.select_by_value('bar')


def testSelectByVisibleTextSingle(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        for x in range(len(select['values'])):
            print(select['values'][x])
            sel.select_by_visible_text(select['values'][x])
            assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_chrome(
    reason='https://bugs.chromium.org/p/chromedriver/issues/detail?id=822')
@pytest.mark.xfail_phantomjs
def testSelectByVisibleTextShouldNormalizeSpaces(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValuesWithSpaces]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        for x in range(len(select['values'])):
            print(select['values'][x])
            sel.select_by_visible_text(select['values'][x])
            assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_chrome
@pytest.mark.xfail_firefox
@pytest.mark.xfail_remote
@pytest.mark.xfail_marionette(raises=InvalidElementStateException)
@pytest.mark.xfail_phantomjs
@pytest.mark.xfail_safari
def testSelectDisabledByVisibleTextShouldThrowException(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
    with pytest.raises(ElementNotSelectableException):
        sel.select_by_visible_text('Bar')


def testSelectByIndexMultiple(driver, pages):
    pages.load("formPage.html")

    for select in [multiSelectValues1, multiSelectValues2]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        sel.deselect_all()
        for x in range(len(select['values'])):
            sel.select_by_index(x)
            selected = sel.all_selected_options
            assert len(selected) == x + 1
            for j in range(len(selected)):
                assert selected[j].text == select['values'][j]

<commit_msg>[py] w3c compliant browsers do not throw exception when clicking on a disabled element<commit_after># Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

import pytest

from selenium.common.exceptions import (
    ElementNotSelectableException,
    InvalidElementStateException,
    NoSuchElementException,
    UnexpectedTagNameException)
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By

disabledSelect = {'name': 'no-select', 'values': ['Foo']}
singleSelectValues1 = {'name': 'selectomatic', 'values': ['One', 'Two', 'Four', 'Still learning how to count, apparently']}
singleSelectValues2 = {'name': 'redirect', 'values': ['One', 'Two']}
singleSelectValuesWithSpaces = {'name': 'select_with_spaces', 'values': ['One', 'Two', 'Four', 'Still learning how to count, apparently']}
multiSelectValues1 = {'name': 'multi', 'values': ['Eggs', 'Ham', 'Sausages', 'Onion gravy']}
multiSelectValues2 = {'name': 'select_empty_multiple', 'values': ['select_1', 'select_2', 'select_3', 'select_4']}


def testSelectByIndexSingle(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        for x in range(len(select['values'])):
            sel.select_by_index(x)
            assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_chrome
@pytest.mark.xfail_firefox
@pytest.mark.xfail_remote
@pytest.mark.xfail_marionette
@pytest.mark.xfail_phantomjs
@pytest.mark.xfail_safari
def testSelectDisabledByIndexShouldThrowException(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
    with pytest.raises(ElementNotSelectableException):
        sel.select_by_index(1)


def testSelectByValueSingle(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        for x in range(len(select['values'])):
            sel.select_by_value(select['values'][x].lower())
            assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_chrome
@pytest.mark.xfail_firefox
@pytest.mark.xfail_remote
@pytest.mark.xfail_marionette
@pytest.mark.xfail_phantomjs
@pytest.mark.xfail_safari
def testSelectDisabledByValueShouldThrowException(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
    with pytest.raises(ElementNotSelectableException):
        sel.select_by_value('bar')


def testSelectByVisibleTextSingle(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        for x in range(len(select['values'])):
            print(select['values'][x])
            sel.select_by_visible_text(select['values'][x])
            assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_chrome(
    reason='https://bugs.chromium.org/p/chromedriver/issues/detail?id=822')
@pytest.mark.xfail_phantomjs
def testSelectByVisibleTextShouldNormalizeSpaces(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValuesWithSpaces]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        for x in range(len(select['values'])):
            print(select['values'][x])
            sel.select_by_visible_text(select['values'][x])
            assert sel.first_selected_option.text == select['values'][x]


@pytest.mark.xfail_chrome
@pytest.mark.xfail_firefox
@pytest.mark.xfail_remote
@pytest.mark.xfail_marionette
@pytest.mark.xfail_phantomjs
@pytest.mark.xfail_safari
def testSelectDisabledByVisibleTextShouldThrowException(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect['name']))
    with pytest.raises(ElementNotSelectableException):
        sel.select_by_visible_text('Bar')


def testSelectByIndexMultiple(driver, pages):
    pages.load("formPage.html")

    for select in [multiSelectValues1, multiSelectValues2]:
        sel = Select(driver.find_element(By.NAME, select['name']))
        sel.deselect_all()
        for x in range(len(select['values'])):
            sel.select_by_index(x)
            selected = sel.all_selected_options
            assert len(selected) == x + 1
            for j in range(len(selected)):
                assert selected[j].text == select['values'][j]


{'fraction_non_alphanumeric': 0.12509484066767831, 'fraction_numerical': 0.00426783004552352, 'mean_word_length': 4.621002132196162, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7387983', 'n_tokens_mistral': 3203, 'n_tokens_neox': 3188, 'n_words': 701}