尝试使用selenium更改元素的值

时间:2017-10-23 03:31:47

标签: javascript python selenium pycharm

我正在尝试使用发送键使用selenium更改元素,但它没有改变。我也尝试使用execute_script,但值没有改变。我正在尝试更改为value = R

driver.find_element_by_name('wlw-select_key:{actionForm.terminal}').send_keys('R')   

<select name="wlw-select_key:{actionForm.terminal}">
<option value="ALL">ALL</option>
<option value="T">1</option>
<option value="K">2</option>
<option value="B">3</option>
<option value="P">4</option>
<option value="Q">5</option>
<option value="R">6</option>
<option value="V">7</option>
<option value="W">8</option>
<option value="G">9</option></select>

2 个答案:

答案 0 :(得分:0)

使用文档http://selenium-python.readthedocs.io/navigating.html

中提供的- (void)drawRect:(NSRect)dirtyRect { dispatch_semaphore_wait(inflightSemaphore, DISPATCH_TIME_FOREVER); [super drawRect:dirtyRect]; … id<MTLTexture> theTexture = … [renderedQueue addObject:theTexture]; // populate secondary views for (BoardMonitorMTKView *v in self.downstreamOutputs) [v enqueueTexture:(hasValidContent) ? [renderedQueue firstObject] : nil]; __block dispatch_semaphore_t fSemaphore = inflightSemaphore; __weak __block NSMutableArray *rQueue = renderedQueue; [commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> buffer) { if ([rQueue count]==2) [rQueue removeObjectAtIndex:0]; dispatch_semaphore_signal(fSemaphore); }]; [commandBuffer presentDrawable:self.currentDrawable]; [commandBuffer commit]; }
  

如您所见,这不是处理SELECT元素的最有效方法。 WebDriver的支持类包括一个名为“Select”的支持类,它提供了与这些相互作用的有用方法:

-(void)enqueueTexture:(id<MTLTexture>)inputTexture {
    dispatch_semaphore_wait(inflightSemaphore2, DISPATCH_TIME_FOREVER);
    if (inputTexture) {
        [textureQueue addObject:inputTexture];
        if ([textureQueue count]>kTextureQueueCapacity)
            [textureQueue removeObject:[textureQueue firstObject]];
    }
    dispatch_semaphore_signal(inflightSemaphore2);

    dispatch_queue_t aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
    dispatch_async(aQueue, ^{
        [self draw];
    });
}

- (void)drawRect:(NSRect)dirtyRect {
    dispatch_semaphore_wait(inflightSemaphore2, DISPATCH_TIME_FOREVER);
    [super drawRect:dirtyRect];
    …
    id<MTLTexture>inputTexture = [textureQueue firstObject];

    MTLRenderPassDescriptor *renderPassDescriptor = self.currentRenderPassDescriptor;
    id<MTLRenderCommandEncoder> encoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];
    MTLViewport viewPort = {0.0, 0.0, (double)self.drawableSize.width, (double)self.drawableSize.height, -1.0, 1.0};
    [encoder setViewport:viewPort];
    [encoder setRenderPipelineState:metalVertexPipelineState];

    // draw main content
    NSUInteger vSize = _vertexInfo.metalVertexCount*sizeof(AAPLVertex);
    id<MTLBuffer> mBuff = [self.device newBufferWithBytes:_vertexInfo.metalVertices
                                                   length:vSize
                                                  options:MTLResourceStorageModeShared];
    [encoder setVertexBuffer:mBuff offset:0 atIndex:0];
    [encoder setVertexBytes:&_viewportSize length:sizeof(_viewportSize) atIndex:1];
    [encoder setFragmentTexture:inputTexture atIndex:0];
    [encoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:_vertexInfo.metalVertexCount];
    [encoder endEncoding];

    __block dispatch_semaphore_t fSemaphore = inflightSemaphore2;
    [commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> buffer) {
        [textureQueue removeObject:[textureQueue firstObject]];
        dispatch_semaphore_signal(fSemaphore);
    }];

    [commandBuffer presentDrawable:self.currentDrawable];
    [commandBuffer commit];
}

答案 1 :(得分:0)

您可以先单击“选择”按钮,然后从显示为

的所有选项中选择正确的选项
driver.find_element_by_xpath("//select[@name='wlw-select_key {actionForm.terminal}']").click()
driver.find_element_by_xpath("//option[@value='R']").click()

这不是解决此问题的优雅方法,但它很简单。