Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Python Selenium刮取隐藏的select元素_Python_Selenium_Select_Element_Hidden - Fatal编程技术网

如何使用Python Selenium刮取隐藏的select元素

如何使用Python Selenium刮取隐藏的select元素,python,selenium,select,element,hidden,Python,Selenium,Select,Element,Hidden,当使用Python Selenium刮取带有隐藏下拉选择元素的网页时,我得到了消息“ElementNotInteractiableException:element无法滚动到视图中” 以下是网页的部分: <select class="period-selection select2-hidden-accessible" tabindex="-1" aria-hidden="true" style=""> <option value="quarterly">Quarterl

当使用Python Selenium刮取带有隐藏下拉选择元素的网页时,我得到了消息“ElementNotInteractiableException:element无法滚动到视图中”

以下是网页的部分:

<select class="period-selection select2-hidden-accessible" tabindex="-1" aria-hidden="true" style="">
<option value="quarterly">Quarterly</option>
<option value="annual" selected="selected">Annual</option>
<option value="ttm">TTM by Quarter</option></select>
我还看到了使用

PeriodType = driver.find_element_by_css_selector('.period-selection')
driver.execute_script("arguments[0].scrollIntoView();", PeriodType)
但到目前为止,这对我也不起作用,或者我不知道如何实施

我还尝试将WebDriverWait用作: PeriodType=driver。通过xpath(//select[@class='period-selection select2 hidden accessible'])查找元素 下拉菜单=选择(周期类型) WebDriverWait(driver,10).until(EC.element可点击((By.XPATH,//select[@class='period-selection select2 hidden accessible']///options[contains('Quarterly')])) 下拉菜单。按可视文本(“季度”)选择

然而,我得到了“raise TimeoutException(消息、屏幕、堆栈跟踪)

带有上述代码的TimeoutException”消息

我希望能够自动选择
季刊

“aria hidden”并不意味着元素是隐藏的,aria代表可访问的富互联网应用程序,目的是让残疾人更容易访问应用程序

此错误意味着某些内容(例如其他元素)位于元素的顶部(覆盖)

尝试在使用元素之前滚动到元素,如:

dropdown=driver.find_element_by_css_selector('.period selection'))
动作=动作链(驱动程序)
操作。将\移动到\元素(下拉菜单)。执行()
选择(下拉菜单)。按可视文本(“季度”)选择
您需要导入ActionChains

来自selenium.webdriver.common.action\u链导入ActionChains

尝试使用
PeriodType=driver。通过xpath(//select[@class='period-selection select2 hidden accessible'])查找元素
如果要选择项目
quarterly
请尝试使用
driver。通过xpath(//select[@class='period-selection select2 hidden accessible']]/option[.='quarterly'])查找元素。单击(),谢谢你,我尝试了你上面的最后一个建议,但仍然得到了:elementnotinteractivatableexception:元素无法滚动到view@DebanjanB,谢谢,但我根据您建议的链接尝试了WebDriverWait方法,并在最初发布我的问题之前收到了TimeoutException消息,因此,我认为我的问题没有重复,至少据我所知还没有。我期待着您的建议。谢谢你。@BinChen又增加了一个标准目标。让我知道它是否有用。如果在某些情况下元素通过CSS隐藏,您将无法使用Select,并且需要按照@supputuri注释进行操作,或者在最坏的情况下,您需要编辑元素。您好@Spencer Melo,当我尝试上面的“actions.move_to_element(dropdown.perform()”时,我得到了“AttributeError:move_to requires a WebElement”。请告知。谢谢。尝试移动到选择之外,按照代码:
dropdown=driver.find\u element\u by\u css\u selector('.period selection')actions=ActionChains(driver)actions.move\u to\u element(dropdown)。perform()选择(dropdown)。select\u by\u visible\u text('Quarterly')
我更新了答案,如果您无法解决,让我们在聊天中试试。嗨,斯宾塞·梅洛,谢谢你,但我是Stackoverflow的新手,我还没有聊天特权。仍然无法解决这个问题。我的电子邮件是binchen。bin@gmail.com. 非常感谢。
PeriodType = driver.find_element_by_css_selector('.period-selection')
driver.execute_script("arguments[0].scrollIntoView();", PeriodType)