Selenium可以识别输入字段(使用xpath完成),但是我无法向其发送任何键。没有错误,但是我要写入键中的文本没有显示在搜索框中。输入字段位于多个div内,并且位于iframe中,但是我敢肯定我已经照顾好了。我该怎么做才能解决此问题?
driver.implicitly_wait(20)
search = driver.find_element_by_xpath("/html/body/main/div/div/div/div[1]/div/div/div/div/div/div[2]/div/input")
search.send_keys("25%)")
输入字段也没有ID,也没有类型,因此,我不太确定除xpath之外还如何找到它。
答案 0 :(得分:0)
我不确定Java和Python之间的区别,但我的建议是您尝试使用JavaScriptExecutor输入密钥:
获取元素的Python代码:
'Acquisition Type'
您基本上在Java中以这种方式传递元素:
public class MainFragment extends BaseFragment<BeanEntity> {
@Override protected int initLayoutId() {
return R.layout.activity_main;
}
@Override public void initView(View view, Bundle savedInstanceState) {
super.initView(view, savedInstanceState);
/*
*An unexpected situation occurred when I executed the following code
*/
String s = new Gson().toJson(mCurrentUser);
LogUtil.e(s);
}
}
很多时候,当SendKeys不起作用时,它就起作用
答案 1 :(得分:-1)
使用类来查找div元素:
(...)
.then(function(result){
return new Promise(function(resolve, reject){
someThingWithCallback(result, function(err, data){
resolve(data)
})
})
})
.then(function(data){
...
})
顺便说一句:
<ipython-input-14-db5a32a0c488> in <module>
9
10 with tf.Graph().as_default():
---> 11 train(get_batches(input_images), input_images.shape)
<ipython-input-11-73fe85d9d0bc> in train(get_batches, data_shape, checkpoint_to_load)
1 def train(get_batches, data_shape, checkpoint_to_load=None):
2 input_images, input_z, lr_G, lr_D = model_inputs(data_shape[1:], NOISE_SIZE)
----> 3 d_loss, g_loss = model_loss(input_images, input_z, data_shape[3])
4 d_opt, g_opt = model_optimizers(d_loss, g_loss)
5
IndexError: tuple index out of range```
I don't understand why I'm getting this error message, as I've followed the tutorial and copied the same code...
Any help greatly appreciated, been trying to figure this out for a week now, but relatively new to python.
Thank you !!