我正在尝试使用硒访问网站,但出现错误
我使用了以下代码,我尝试过header('Access-Control-Allow-Origin: *');
,但对我不起作用
require_once "phpwebdriver/WebDriver.php";
$webdriver = new WebDriver("localhost",4444);
//$ffprofile = $webdriver->prepareBrowserProfile("");
$webdriver->connect("chrome");
$webdriver->get("https://healofy.com/"); sleep(3);
$element=$webdriver->findElementBy(LocatorStrategy::id,"Baby_1_2_years");
if($element) {
print_r($element);
$element->click();
}
答案 0 :(得分:1)
可能是您使用的是旧版php webdriver client(2013年)?与当前的硒和浏览器不兼容。
使用更新的PHP硒facebook/webdriver,然后使用设置步骤:
DATA: rt_data TYPE REF TO data,
ls_key TYPE /bobf/s_frw_key,
lt_key TYPE /bobf/t_frw_key.
FIELD-SYMBOLS: <fs_data> TYPE any,
<fs_feld_fu_key> TYPE any,
<fs_feld_walzzyk> TYPE any.
CREATE DATA rt_data LIKE LINE OF ct_data.
ASSIGN rt_data->* TO <fs_data>.
IF <fs_data> IS ASSIGNED.
LOOP AT ct_data INTO <fs_data>.
ASSIGN COMPONENT 'fu_key' OF STRUCTURE <fs_data> TO <fs_feld_fu_key>.
IF <fs_feld_fu_key> IS ASSIGNED.
ls_key-key = <fs_feld_fu_key>.
APPEND ls_key TO lt_key.
ENDIF.
ENDLOOP.
ENDIF.
/scmtms/cl_tor_helper_read=>get_tor_data(
EXPORTING
it_root_key = lt_key
IMPORTING
et_mci_items = DATA(lt_mci_items)
).
LOOP AT lt_mci_items ASSIGNING FIELD-SYMBOL(<fs_mci_items>).
LOOP AT ct_data INTO <fs_data>.
ASSIGN COMPONENT 'FU_KEY' OF STRUCTURE <fs_data> TO <fs_feld_fu_key>.
IF <fs_feld_fu_key> IS ASSIGNED.
IF <fs_feld_fu_key> = <fs_mci_items>-parent_key.
ASSIGN COMPONENT 'ZZ_CHANGED_FIELD' OF STRUCTURE <fs_data> TO <fs_feld_walzzyk>.
IF <fs_feld_walzzyk> IS ASSIGNED.
<fs_feld_walzzyk> = <fs_mci_items>-zz_walzzyklus.
MODIFY TABLE ct_data FROM <fs_data>.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
如果缺少某些内容,请阅读上面的github页面。
和PHP代码
# if you have composer
composer require facebook/webdriver
# if not download composer.phar
curl -sS https://getcomposer.org/installer | php
php composer.phar require facebook/webdriver